0

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

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

问题是:动画完成后视图的实际坐标会被重置。动画完成后视图是否可能保持在新坐标?

谢谢。

4

1 回答 1

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/

于 2012-01-13T20:29:33.087 回答