阅读更多
2D仿射变换
UIView的transform属性是一个CGAffineTransform类型,用于在二维空间做旋转,缩放和平移。CGAffineTransform是一个可以和二维空间向量(例如CGPoint)做乘法的3X2的矩阵:
1240
Paste_Image.png
当对UIView应用变换矩阵,UIView图层矩形内的每一个点都被相应地做变换,从而形成一个新的四边形的形状。CGAffineTransform中的“仿射”的意思是无论变换矩阵用什么值,图层中平行的两条线在变换之后任然保持平行.
单位矩阵
CGAffineTransformIdentity
CGAffineTransform transform = CGAffineTransformIdentity;
结果:
(CGAffineTransform) transform = (a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0)
创建仿射变换矩阵
CGAffineTransformMakeRotation(CGFloat angle) // 旋转
CGAffineTransformMakeScale(CGFloat sx, CGFloat sy) // 缩放
CGAffineTransformMakeTranslation(CGFloat tx, CGFloat ty) // 平移
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI_4);
结果 :
(CGAffineTransform) transform = (a = 0.70710678118654757, b = 0.70710678118654746, c = -0.70710678118654746, d = 0.70710678118654757, tx = 0, ty = 0)
CGAffineTransform transform = CGAffineTransformMakeScale(0.8, 0.8);
结果:
(CGAffineTransform) transform = (a = 0.80000000000000004, b = 0, c = 0, d = 0.80000000000000004, tx = 0, ty = 0)
CGAffineTransform transform = CGAffineTransformMakeTranslation(10, 10);
结果:
(CGAffineTransform) transform = (a = 1, b = 0, c = 0, d = 1, tx = 10, ty = 10)
1240
Paste_Image.png
图中,灰色为旧图,蓝色为变化后的新图.
阅读全文直接点击: http://click.aliyun.com/m/10253/