【问题标题】:How to add bounce effect to UIView animateWithDuration如何向 UIView animateWithDuration 添加反弹效果
【发布时间】:2015-07-16 04:10:47
【问题描述】:

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

[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。

【问题讨论】:

  • 这不是我要找的反弹动画。
  • 动画按预期工作。这不是您想要的。您必须在当前代码的完成块中添加一个简单的 animateWithDuration: 块。 或者正如muku指出的那样,使用UIDynamicAnimator

标签: ios objective-c animation animatewithduration


【解决方案1】:

用于将来的代码重用和保持代码干净

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

【讨论】:

    【解决方案2】:

    UIView弹跳动画的详细解释在这篇文章中,UIDynamicAnimator和spring Animation都有

    How to create a UIView bounce animation?

    【讨论】:

      猜你喜欢
      • 2016-03-02
      • 1970-01-01
      • 1970-01-01
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多