CAShapeLayer路径动画 - 缩小圆圈

时间:2014-03-06 00:33:54

标签: ios core-animation calayer

我正在尝试缩小循环CAShapeLayer,但使用关键路径'path'似乎不起作用。

CGPathRef startPath = [UIBezierPath bezierPathWithOvalInRect:startRect].CGPath;
CGPathRef endPath   = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(startRect, 15, 15)].CGPath;

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.duration          = 1.0;
animation.fromValue         = (__bridge id)startPath;
animation.toValue           = (__bridge id)endPath;
animation.autoreverses      = YES;
animation.repeatCount       = CGFLOAT_MAX;
animation.timingFunction    = [CAMediaTimingFunction functionWithControlPoints:0.6 :0.3 :0.8 :0.45];

//circleLayer is a CAShapeLayer
[self.circleLayer addAnimation:animation forKey:@"pathAnimation"];

我认为我必须误解路径动画是如何工作的,因为如果我尝试动画,例如不透明度或变换,几乎相同的代码似乎工作正常。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我最近遇到了同样的问题,最后通过创建圆圈解决了问题,然后设置了CGAffineTransform缩放的动画。在图层为圆的视图中,我只使用

CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformScale(transform, scaleX, scaleY);

[UIView animateWithDuration: 0.5 animations: ^{
    self.transform = transform;
}];

希望这有帮助!