CATransform3D 特效

来源:互联网 发布:淘宝店的排名怎么上去 编辑:程序博客网 时间:2024/04/30 13:25

  首先要了解一些position和anchorPoint的知识,详情见本人的博客http://blog.csdn.net/victor_barnett/article/details/50547632


CATransform3D 的数据结构定义了一个同质的三维变换(4x4 CGFloat值的矩阵),用于图层的旋转,缩放,偏移,歪斜和应用的透视。


图层的2个属性指定了变换矩阵:transform 和 sublayerTransform。

transform : 是结合 anchorPoint(锚点)的位置来对图层和图层上的子图层进行变化。

sublayerTransform:是结合anchorPoint(锚点)的位置来对图层的子图层进行变化,不包括本身。


CATransform3DIdentity 是单位矩阵,该矩阵没有缩放,旋转,歪斜,透视。该矩阵应用到图层上,就是设置默认值。


变换函数

CATransform3DMakeTranslation 

官方文档:

Returns a transform that translates by '(tx, ty, tz)'. t' = [1 0 0 0; 0 1 0 0; 0 0 1 0; tx ty tz 1].CATransform3D CATransform3DMakeTranslation (CGFloat tx, CGFloat ty, CGFloat tz)。

做一个解释,对于初学者来说,可能没有看明白是什么意思。我详细说下

对于CATransform3D来说,它是一个4x4 CGFloat的矩阵。

而上面给的值:[1 0 0 0; 0 1 0 0; 0 0 1 0; tx ty tz 1].

给竖起来后。就发现:

1    0    0    0

0    1    0    0

0    0    1    0

tx  ty   tz   1

竖起来看就很明显了。

CATransform3D 又是一个结构。他有自己的一个公式,可以进行套用。

struct CATransform3D

{

 CGFloat m11(x缩放), m12(y切变), m13(旋转), m14;

 CGFloat m21(x切变), m22(y缩放), m23, m24;

 CGFloat m31(旋转), m32, m33(缩放), m34(透视效果,要操作的这个对象要有旋转的角度,否则没有效果.正直/负值都有意义);

 CGFloat m41(x平移), m42(y平移), m43(z平移), m44;

};

CATransform3D CATransform3DMakeTranslation (CGFloat tx,CGFloat ty,CGFloat tz)

tx::x平移。  ty:y平移。  tz:z平移

tx:X轴偏移位置,往下为正数。

ty:Y轴偏移位置,往右为正数。

tz:Z轴偏移位置,往外为正数。


CATransform3D CATransform3DMakeScale (CGFloat sx,CGFloat sy,CGFloat sz) 

/* Returns a transform that scales by `(sx, sy, sz)': t' = [sx 0 0 0; 0 sy 0 0; 0 0 sz 0; 0 0 0 1]. */

缩放效果:

sx:X轴缩放,代表一个缩放比例,一般都是 0 --- 1 之间的数字。

sy:Y轴缩放。

sz:整体比例变换时,也就是m11(sx)== m22(sy)时,若m33(sz)>1,图形整体缩小,若0<m33(sz)<1,图形整体放大,若m33(sz)<0,发生关于原点的对称等比变换


CATransform3D CATransform3DMakeRotation (CGFloat angle,CGFloat x,CGFloat y,CGFloat z)

/* Returns a transform that rotates by 'angle' radians about the vector '(x, y, z)'. If the vector has length zero the identity transform is returned. */

返回一个旋转角的弧度向量为(x,y,z)的变换,如果为0返回单位矩阵

旋转效果:

angle:旋转的弧度,所以要把角度转换成弧度:角度 * M_PI / 180。

x:向X轴方向旋转。值范围-1 --- 1之间

y:向Y轴方向旋转。值范围-1 --- 1之间

z:向Z轴方向旋转。值范围-1 --- 1之间


CATransform3D CATransform3DTranslate (CATransform3D t,CGFloat tx,CGFloat ty,CGFloat tz)

/* Translate 't' by '(tx, ty, tz)' and return the result: t' = translate(tx, ty, tz) * t. */

CATransform3D CATransform3DScale (CATransform3D t,CGFloat sx,CGFloat sy,CGFloat sz)

/* Scale 't' by '(sx, sy, sz)' and return the result: t' = scale(sx, sy, sz) * t. */

CATransform3D CATransform3DRotate (CATransform3D t,CGFloat angle, CGFloat x,CGFloat y,CGFloat z)

/* Rotate 't' by 'angle' radians about the vector '(x, y, z)' and return the result. If the vector has zero length the behavior is undefined: t' = rotation(angle, x, y, z) * t. */

t:就是上一个函数。其他的都一样。就可以理解为:函数的叠加,效果的叠加。


CATransform3D CATransform3DConcat (CATransform3D a,CATransform3D b)

/* Concatenate 'b' to 'a' and return the result: t' = a * b. */

 a函数的效果叠加b函数的效果

CATransform3D CATransform3DInvert (CATransform3D t)

/* Invert 't' and return the result. Returns the original matrix if 't'has no inverse. */

翻转矩阵“t”并返回结果。如果矩阵' t '*没有翻转矩阵返回原始矩阵


CATransform3D CATransform3DMakeAffineTransform (CGAffineTransform m)

bool CATransform3DIsAffine (CATransform3D t)

仿射效果。

就是把一个 CATransform3D 对象转换成一个 CGAffineTransform 对象。

也就是把 CATransform3D 矩阵 转换成 CGAffineTransform 矩阵




0 0
原创粉丝点击