在CAKeyframeAnimation之后,Layer.frame没有更新?

时间:2009-03-22 05:39:48

标签: iphone objective-c

我正在尝试为图层的位置设置动画。它动画,但它的帧属性在动画结束时不会更新,似乎只有它的presentationLayer。这就是我正在做的事情:

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint   (path, NULL, layer.frame.origin.x, layer.frame.origin.y);
CGPathAddLineToPoint(path, NULL, 20,  20);
CGPathAddLineToPoint(path, NULL, 20,  460);
CGPathAddLineToPoint(path, NULL, 300, 460);

CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = path;
animation.calculationMode = kCAAnimationPaced;
animation.repeatCount = 0;
animation.autoreverses = NO;

CAAnimationGroup *theGroup = [CAAnimationGroup animation];
theGroup.animations = [NSArray arrayWithObject:animation];
theGroup.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
theGroup.duration = 2;
theGroup.removedOnCompletion = NO;
theGroup.fillMode = kCAFillModeForwards;
CFRelease(path);

[layer addAnimation:theGroup forKey:@"animatePosition"];

动画完成后,图层位于正确的目的地,但是当我查询其帧值时,它表示它仍处于原始位置!何时/何地/如何使frame属性与图层的presentationLayer框架属性同步?

由于

1 个答案:

答案 0 :(得分:1)

动画实际上不会更改底层的任何值。要在最后一行之后立即更新实际帧值,只需将帧设置为新值即可。然后你可以摆脱removedOnCompletion = NO;

只要动画不是附加的,动画就会根据您输入的数据运行,在动画完成之前,设置实际的帧对显示没有任何影响。