Core Animation笔记(变换)
1.仿射变换
CGAffineTransformMakeScale :
CGAffineTransformMakeTranslation
CGAffineTransformMakeRotation(CGFloat angle)
CGAffineTransform scaleTrans = CGAffineTransformMakeScale(1.2, 1.2); CGAffineTransform tanslation = CGAffineTransformMakeTranslation(0, 100); //复合两个变换受,第二个受到第一个影响,所以这里位移小于100 CGAffineTransform compact = CGAffineTransformConcat(scaleTrans, tanslation self.imgView.layer.affineTransform = compact;
//生成一个初始化的空值 单位矩阵 CGAffineTransform indentity = CGAffineTransformIdentity; indentity = CGAffineTransformRotate(indentity, M_PI/2); //这里是右移 但实际效果是左移动,因为在之前做个旋转变换,上个变换会影响到下个变换,也就是说位移变换也要旋转90度相当于向左移! indentity = CGAffineTransformTranslate(indentity, 0, 200) ;
self.imgView.layer.affineTransform = indentity;
2.3D 效果
//透视效果 CATransform3D indentity3d = CATransform3DIdentity; //设置m34来设置透视效果(看上去有立体感) indentity3d.m34 = -1.0/500; indentity3d = CATransform3DRotate(indentity3d, M_PI/4, 0, 1, 0); self.imgView.layer.transform = indentity3d; //是否绘制背面图形,默认YES 即图层的背面是正面的镜像 self.imgView.layer.doubleSided = true; //为子类图层添加变换 self.containerView.layer.sublayerTransform = indentity3d;