CAShapeLayer路径动画 – 缩小圆圈

我正在尝试缩小循环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"]; 

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

有任何想法吗?

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

 CGAffineTransform transform = CGAffineTransformIdentity; transform = CGAffineTransformScale(transform, scaleX, scaleY); [UIView animateWithDuration: 0.5 animations: ^{ self.transform = transform; }]; 

希望这可以帮助!