【问题标题】:Is it possible to play a path backwards in a CAKeyFrameAnimation?是否可以在 CAKeyFrameAnimation 中向后播放路径?
【发布时间】:2009-04-03 20:13:29
【问题描述】:

我想根据 CGPath 为 CALayer 的位置设置动画,但我想倒着播放。

有没有办法让路径向后动画,或反转 CGPath?

【问题讨论】:

    标签: iphone objective-c core-animation cgpath


    【解决方案1】:
    animation.speed = -1;
    

    ?

    【讨论】:

    • 是的。那肯定更好。我希望我早点想到这一点。
    • 你在哪里学的?我在苹果文档中找不到这个功能。
    【解决方案2】:

    这可能不是最好的解决方案,但它对我有用。我让动画自动反转,然后在中途开始它。但为了防止它再次动画回来,我需要提前终止它。

    - (void) animate {
        CAKeyframeAnimation * pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        pathAnimation.path = path;
        pathAnimation.duration = 15.0;
        pathAnimation.calculationMode = kCAAnimationPaced;
        pathAnimation.timeOffset = pathAnimation.duration;
        pathAnimation.autoreverses = YES;
    
        NSString * key = @"pathAnimation";
        [animatedView.layer addAnimation:pathAnimation forKey:key];
        [NSTimer scheduledTimerWithTimeInterval:pathAnimation.duration target:self selector:@selector(endAnimation:) userInfo:key repeats:NO];
    }
    
    - (void) endAnimation:(NSTimer *)timer {
        [animatedView.layer removeAnimationForKey:timer.userInfo];
    }
    

    如果有更好的方法,我想知道。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      • 2017-03-16
      • 2014-12-18
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      • 2020-06-20
      相关资源
      最近更新 更多