美文网首页很屌的项目运用
iOS开发篇小知识 - CATransform3D的基本属性

iOS开发篇小知识 - CATransform3D的基本属性

作者: lucifrom_long | 来源:发表于2016-01-08 09:38 被阅读3844次

structCATransform3D

{CGFloatm11(x缩放), m12(y切变), m13(旋转), m14;

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

CGFloatm31(旋转), m32, m33, m34(透视效果,要操作的对象要有旋转的角度,不然没效果);

CGFloatm41(x平移), m42(y平移), m43(z平移), m44;};

m34透视效果,一般通过-1.0/d来应用透视效果,d代表想象中视觉相机与屏幕之间的距离,以像素为单位,通常500-1000j就已经很好了。

注:使用3D变换的时候要注意灭点,统一设置所有图层共享一个灭点

CATransform3D perspective = CATransform3DIdentity;

perspective.m34 = - 1.0 / 500.0;

self.containerView.layer.sublayerTransform = perspective;

CATransform3DMakeTranslation (CGFloat tx, CGFloat ty, CGFloattz)

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

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

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

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

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

sy:Y轴缩放。

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

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

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

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

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

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

CATransform3DContact 把动作combine在一起

相关文章

网友评论

  • 绝不知火:所以在我们完成layer动画之后,最好将我们的layer属性设置为我们最终状态的属性,然后将presentation layer 移除掉。

    具体怎么弄呀

    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 25.0;
    rotationAnimation.repeatCount = HUGE_VALF;
    [CATransaction setDisableActions:YES];
    [self.imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

    之后想要保持 self .imageview的状态
    CATransform3D trans = self.imageView.layer.transform;
    [self.imageView.layer removeAnimationForKey:@"rotationAnimation"];
    self.imageView.layer.transform = trans;
    不行啊

本文标题:iOS开发篇小知识 - CATransform3D的基本属性

本文链接:https://www.haomeiwen.com/subject/yuifkttx.html