CAAnimation:动画后不重置

发布于 2024-12-27 02:01:02 字数 472 浏览 0 评论 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"];

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

谢谢。

I have this code to move a view.

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

The problem is: The actual coordinates of the view get reseted after the animation has finished. Is it possible that the view remains at the new coordinates after the animation has finished?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山川志 2025-01-03 02:01:02

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

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

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

In addition to attaching an animation that animates the property, you have to actually set the property to its final value. Crazy, isn't it? Try doing this before you add the animation:

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

I strongly recommend watching the WWDC 2011 video "Core Animation Essentials". It explains this, and covers a lot of useful information for anyone using Core Animation. You can find it here: https://developer.apple.com/videos/wwdc/2011/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文