美文网首页
图层学习笔记

图层学习笔记

作者: 三三哥 | 来源:发表于2017-08-23 12:15 被阅读0次

    记录一下图层学习——放射变换在显示动画上的应用 ,

    原文链接https://zsisme.gitbooks.io/ios-/content/chapter8/property-animations.html

        放射变换的知识在这里就不说了

    直接上代码

    CALayer *shipLayer = [CALayer layer];

    shipLayer.frame = CGRectMake(0, 0, 128, 128);

    shipLayer.position = CGPointMake(150, 150);

    shipLayer.contents = (__bridge id)[UIImage imageNamed: @"Ship.png"].CGImage;

    [self.containerView.layer addSublayer:shipLayer];

    //animate the ship rotation

    CABasicAnimation *animation = [CABasicAnimation animation];

    animation.keyPath = @"transform.rotation";

    animation.duration = 2.0;

    animation.byValue = @(M_PI * 2);

    [shipLayer addAnimation:animation forKey:nil];

    CABasicAnimation 属性动画对layer 的transform这个属性做动画,其实就是放射变换结合动画

    transform.rotation 这个其实不是transform 的实际属性,因为transform 是结构体。但是我们可以认为是transform的虚拟属性,举一反三 transform.position或者transform.scale 也是同样的道理!

    利用transform.rotation 的属性好处体现在一点 那就是 可以“连续变换” ,不太好解释。

    举个例子

    把上述代码的animation.keyPath = @"transform.rotation"; 换成animation.keyPath = @"transform";你会发现什么变化都没有,因为系统认为M_PI * 2 是360度 转回原始位置所有就不产生动画。并没有做任何旋转,这是因为变换矩阵不能像角度值那样叠加。

    所以才有上面所说的连续变换!

    相关文章

      网友评论

          本文标题:图层学习笔记

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