【发布时间】:2014-03-06 00:33:53
【问题描述】:
我正在尝试缩小圆形 CAShapeLayer,但使用关键路径“路径”似乎不起作用。
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"];
我想我一定误解了路径动画的工作原理,因为如果我尝试制作不透明度或变换的动画,几乎相同的代码似乎可以正常工作。
有什么想法吗?
【问题讨论】:
-
在我的脑海中,我无法发现哪里出了问题。我以前可以让very similar code 工作。那么,您能否验证这两条路径是否合理且有效(主要验证 startRect 是否足够大,可以像那样插入)。您可以通过简单地将 endPath 分配给圆形层并验证它是否有效(没有动画)来测试它
-
startRect是什么?如果小于 30x30,则插入时为 CGRectZero,因此endPath可能未定义。因为除此之外,一切看起来都很完美。
标签: ios core-animation calayer