UIView 动画远非流畅

UIView Animation is far from smooth

我正在尝试上下缩放按钮以引起注意。

我尝试了两种动画方式:

方法一

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.autoreverses = YES;
animation.repeatDuration = 2;
animation.duration = 0.4;
animation.fromValue = @(1.0f);
animation.toValue= @(1.2f);
[button.layer addAnimation:animation forKey:@"scale"];

方法二

  CGAffineTransform scaleUp = CGAffineTransformMakeScale(1.2f, 1.2f);
  [UIView animateWithDuration:0.5 delay:1 options:UIViewAnimationOptionAutoreverse
                   animations:^{

                     [button setTransform:scaleUp];

                   } completion:^(BOOL finished) {

                   }];

两个动画都有同样的问题。接近尾声时,当按钮缩小到正常比例时,动画直接跳到比例 1.0。

类似于:

1.2 ... 1.18 ... 1.15 ... 繁荣 ... 1.0

我看到按钮从一个巨大的比例值弹出到 1,而不是平滑的。

您需要设置button.In您案例的最终状态,比例变化如

1.0->1.1->1.2->1.1->1.0 ->1.2(跳转到最终状态)

动图

CGAffineTransform scaleUp = CGAffineTransformMakeScale(1.5f, 1.5f);
[UIView animateWithDuration:0.5 delay:1 options:UIViewAnimationOptionAutoreverse
                 animations:^{

                     [self.button setTransform:scaleUp];

                 } completion:^(BOOL finished) {
                     self.button.transform = CGAffineTransformIdentity;
                 }];