我正在尝试为下面的动画添加反弹效果。这是我的代码:

[UIView animateWithDuration:1.0
                       delay:.0
      usingSpringWithDamping:0.5
       initialSpringVelocity:2.0
                     options:UIViewAnimationOptionCurveEaseOut
                  animations:^{
                      // Coming from a value of CGAffineTransformMakeScale(0.001, 1.0)
                      self.myView.transform = CGAffineTransformMakeScale(1.0, 1.0);
                  }completion:nil
          ];

它工作不正常。它在动画结束时变宽,然后恢复正常。我希望宽度反弹到小于 1.0 的值,不超过 1.0。

最佳答案

用于将来的代码重用和保持代码清洁

popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);

[self.view addSubview:popUp];

[UIView animateWithDuration:0.3/1.5 animations:^{
    popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished) {
    [UIView animateWithDuration:0.3/2 animations:^{
        popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3/2 animations:^{
            popUp.transform = CGAffineTransformIdentity;
        }];
    }];
}];

关于ios - 如何为 UIView animateWithDuration 添加反弹效果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30069694/

10-16 11:49