0
我正在使用CAKeyframeAnimation將CALayer移動到圓形軌跡上。有時我需要停止動畫並將動畫移動到動畫停止點。這裏代碼:CAKeyFrameAnimation表示層似乎不會改變
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對它進行了測試,結果也起作用。 – rdelmar 2015-04-05 00:24:42