【发布时间】:2010-11-17 17:20:00
【问题描述】:
更新:
这里没有问题。原来我每次移动点时都在重新添加动画。在代码中的其他位置,我只是完全掩盖了它。请忽略这个问题。
结束更新
我有一个 UIView,它只是作为 UIImageView 和 CAShaperLayer 的容器。形状层正在绘制一个圆圈,我已经向该形状层添加了一个路径动画以使其脉冲。我希望能够使用 UIView 的 center 属性同时使圆圈脉动并移动容器视图。但是,当我在容器 UIView 上设置 center 属性时,无论它在动画中的哪个位置,脉冲动画都会从头开始重新启动。
如何防止脉冲动画重新启动?
脉冲动画:
CGRect startRect = CGRectMake(-10 + (self.bounds.size.width / 2),
-10 + (self.bounds.size.height / 2),
20,
20);
CGMutablePathRef fromPath = CGPathCreateMutable();
CGPathAddEllipseInRect(fromPath, NULL, startRect);
CGRect endRect = CGRectMake(-20 + (self.bounds.size.width / 2),
-20 + (self.bounds.size.height / 2),
40,
40);
CGMutablePathRef toPath = CGPathCreateMutable();
CGPathAddEllipseInRect(toPath, NULL, endRect);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.fromValue = (id)fromPath;
animation.toValue = (id)toPath;
CGPathRelease(fromPath);
CGPathRelease(toPath);
animation.duration = 2.0f;
animation.repeatCount = HUGE_VALF;
[self.myCircleLayer addAnimation:animation forKey:self.pathAnimationKey];
我通过以下方式移动容器视图:
self.myContainerView.center = newPoint;
【问题讨论】:
标签: iphone core-animation