【发布时间】:2015-04-05 06:21:57
【问题描述】:
我正在使用 CAKeyframeAnimation 在圆形轨迹上移动 CALayer。有时我需要停止动画并将动画移动到动画停止的点。代码如下:
CAKeyframeAnimation* circlePathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
CGMutablePathRef circularPath = the circle path;
circlePathAnimation.path = circularPath;
circlePathAnimation.delegate = self;
circlePathAnimation.duration = 3.0f;
circlePathAnimation.repeatCount = 1;
circlePathAnimation.fillMode = kCAFillModeForwards;
circlePathAnimation.removedOnCompletion = NO;
circlePathAnimation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:.43 :.78 :.69 :.99];
[circlePathAnimation setValue:layer forKey:@"animationLayer"];
[layer addAnimation:circlePathAnimation forKey:@"Rotation"];
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
CALayer *layer = [anim valueForKey:@"animationLayer"];
if (layer) {
CALayer *presentationLayer = layer.presentationLayer;
layer.position = presentationLayer.position;
}
}
但是表示层的位置没有变化!!!我从 ios 8 读到它不再可靠。那么有没有其他方法可以找到动画层的当前位置?
【问题讨论】:
-
我已经获得了使用 iOS 8 中的表示层为对象设置动画的位置(实际上是 frame.origin),而且它似乎工作正常。您能否提供一个参考,说明您在哪里读到它不再可靠?我用presentationLayer.position对其进行了测试,结果也很有效。
标签: ios core-animation calayer cakeyframeanimation