【问题标题】:CAAnimationGroup Running Too FastCAAnimationGroup 运行太快
【发布时间】:2017-09-06 05:05:01
【问题描述】:

我的 CAAnimationGroup 运行速度过快。我希望它总共需要 50 秒来做某事,而它在大约 3 秒内就完成了……它轻而易举地通过第一个动画,而另一个则慢了。

hover = [CABasicAnimation animationWithKeyPath:@"position"];
        hover.fillMode = kCAFillModeForwards;
        hover.removedOnCompletion = NO;
        hover.additive = YES; // fromValue and toValue will be relative instead of absolute values
        hover.fromValue = [NSValue valueWithCGPoint:CGPointZero];
        hover.toValue = [NSValue valueWithCGPoint:CGPointMake(26*22, 26*-10.0)]; // y increases downwards on iOS
        hover.autoreverses = FALSE; // Animate back to normal afterwards

        hover.repeatCount = 0; // The number of times the animation should repeat

       CABasicAnimation *fall = [CABasicAnimation animationWithKeyPath:@"position"];
        fall.fillMode = kCAFillModeForwards;
        fall.removedOnCompletion = NO;
        fall.additive = YES; // fromValue and toValue will be relative instead of absolute values
        fall.fromValue = [NSValue valueWithCGPoint:CGPointMake(26*22, 26*-10.0)];
        fall.toValue = [NSValue valueWithCGPoint:CGPointMake(26*22, guess1*700.0)]; // y increases downwards on iOS
        fall.autoreverses = FALSE; // Animate back to normal afterwards

        fall.repeatCount = 0; // The number of times the animation should repeat

        CAAnimationGroup*   group = [CAAnimationGroup new];
        group.beginTime = 0.;
        [group setDuration:50.0];
        group.animations = @[ hover, fall ];

        [theDude.layer addAnimation:group forKey:@"myHoverAnimation"];

【问题讨论】:

  • 为什么用两个动画来为同一个属性制作动画?我认为这行不通。
  • @macmoonshine 我想让它完成第一个动画,然后运行第二个动画。
  • 你应该改用CAKeyframeAnimation (developer.apple.com/documentation/quartzcore/…)。

标签: ios xcode cabasicanimation caanimation


【解决方案1】:

从你的实现来看,我假设你想要一个对象 theDude 上的 sequence 动画在它的 position 属性上。

您可以使用CATransaction 使用它的完成块来实现动画。更多可以阅读here

【讨论】:

  • CATransaction 不适用于一起排序动画。如果您在 runloop 的同一运行中应用多个事务,则动画都将并行运行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-11
  • 2018-06-16
  • 2020-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-27
相关资源
最近更新 更多