CAShapeLayer 与CABasicAnimation结合使用时strokeStart、strokeEnd 与fromValue、toValue的用法

因为本人在将CAShapeLayer和CABasicAnimation结合使用的时候,遇到了对属性的组合产生的效果弄不清的情况,特意对它们的用法进行了总结。

 1 keyPath = strokeStart  动画的fromValue = 0toValue = 1

     strokeEnd默认为1strokeStart 0  1 strokeStart = 0 时有一条完整的路径,strokeStart = 1  路径消失。效果就是一条从路径起点到终点慢慢的消失

     

     2 keyPath = strokeStart  动画的fromValue = 1toValue = 0     

    strokeEnd默认为1strokeStart 1  0 strokeStart = 1 时无路径,strokeStart = 0  画出一条完整的路径。效果就是一条从路径终点到起点慢慢的出现

     

     3 keyPath = strokeEnd  动画的fromValue = 0toValue = 1

     strokeStart默认为0strokeEnd 0-1strokeEnd=0 时,无路径,strokeEnd=1 时,一条完整路径。效果就是一条路径起点到终点慢慢的出现

     

     4 keyPath = strokeEnd  动画的fromValue = 1toValue = 0

     效果就是一条路径从终点到起点慢慢消失


下面我写了一个简单地用法:

<span style="font-size:18px;">CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.fromValue = @0;
animation.toValue = @1;
animation.duration = 0.5f;
[layer addAnimation:animation forKey:@"strokeEnd"];</span>
效果就是一条路径起点到终点在0.5s的时间内出现

猜你喜欢

转载自blog.csdn.net/u014745414/article/details/44785623