CAAnimation:动画后不要重置

时间:2012-01-13 20:18:02

标签: objective-c xcode caanimation cabasicanimation

我有这个代码来移动视图。

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"];

问题是:动画完成后,视图的实际坐标会重置。动画结束后视图是否可能保留在新坐标处?

感谢。

1 个答案:

答案 0 :(得分: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/

相关问题