【问题标题】:CAAnimation: Don't reset after animationCAAnimation:动画后不要重置
【发布时间】:2012-01-13 20:18:02
【问题描述】:

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

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

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

谢谢。

【问题讨论】:

    标签: objective-c xcode caanimation cabasicanimation


    【解决方案1】:

    除了附加动画来为属性设置动画外,您还必须将属性实际设置为其最终值。疯了,不是吗?在添加动画之前尝试这样做:

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

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

    【讨论】:

    • 谢谢。我找到了另一个答案:[theAnimation setFillMode:kCAFillModeForwards];然后它工作正常。感谢您的链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 2012-03-30
    • 1970-01-01
    相关资源
    最近更新 更多