CGAffineTransform讲解
2018-04-20 本文已影响25人
iOS坚持者
用于绘制平面图形的一个仿射变换矩阵。用于做旋转、缩放、平移,一个仿射变换矩阵是一个3*3的矩阵,只用于 xy坐标,不涉及 z 轴。
struct CGAffineTransform {
CGFloat a, b, c, d;
CGFloat tx, ty;
};

CGAffineTransformIdentity:原始的transform 它的值为[ 1 0 0 1 0 0 ]。
CGAffineTransformMakeTranslation:Return a transform which translates by `(tx, ty)':t' = [ 1 0 0 1 tx ty ];以屏幕左上角为原点,设置view的x,y 方向的偏移,并且不管之前给 view 设置了什么缩放和旋转,a, b, c, d都会回归到原始值。
CGAffineTransformTranslate:t' = [ 1 0 0 1 tx ty ] * t ,在原有基础上再进行偏移

CGAffineTransformMakeScale:[ sx 0 0 sy 0 0 ],X缩放sx倍,y缩放sy倍,其他值为原始值。
CGAffineTransformScale:t' = [ sx 0 0 sy 0 0 ] * t,在原有基础上再进行缩放

CGAffineTransformMakeRotation:[ cos(angle) sin(angle) -sin(angle) cos(angle) 0 0 ],按照角度旋转。
CGAffineTransformRotate:t' = [ cos(angle) sin(angle) -sin(angle) cos(angle) 0 0 ] * t,在原有基础上再进行旋转

CGAffineTransformInvert:根据CGAffineTransformIdentity来颠倒,比如,x 放大就是变成缩小,x 偏移+100,就是变成偏移-100,顺时针旋转90度就是根据初始化位置逆时针旋转90度。
CGAffineTransformIsIdentity:检测一个Transformation是不是恒等变换,也就是说不变。
CGAffineTransformEqualToTransform:检测两个Transformation是否相等。