2012-01-13 55 views
0

我有这段代码来移动视图。CAAnimation:动画后不要重置

CABasicAnimation *theAnimation; 
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; 
theAnimation.duration=1; 
theAnimation.repeatCount=1; 
theAnimation.autoreverses=NO; 
theAnimation.fromValue=[NSNumber numberWithFloat:0]; 
theAnimation.toValue=[NSNumber numberWithFloat:-60]; 
[view.layer addAnimation:theAnimation forKey:@"animateLayer"]; 

问题是:动画完成后,视图的实际坐标被复位。在动画完成后,视图是否可能保留在新的坐标上?

谢谢。

回答

0

除了附加动画动画属性的动画之外,您还必须将属性实际设置为其最终值。疯了,不是吗?尝试在添加动画之前执行此操作:

[view.layer setValue:[NSNumber numberWithFloat:-60] forKey:@"transform.translation.x"]; 

我强烈建议您观看WWDC 2011视频“Core Animation Essentials”。它解释了这一点,并为使用Core Animation的任何人提供了许多有用的信息。你可以在这里找到它:https://developer.apple.com/videos/wwdc/2011/

+0

谢谢。我发现了另一个答案: [theAnimation setFillMode:kCAFillModeForwards]; 然后它工作正常。感谢您的链接。 – user688262 2012-01-13 20:35:27