UIView动画:模拟速度

时间:2013-10-26 23:42:12

标签: ios iphone cocoa-touch core-animation uiviewanimation

我正在尝试使用UIView动画来简单地将视图移动到屏幕上:

  [UIView animateWithDuration:.10 delay:0 options: nil animations:^
   {
       self.menusView.frame = endingMenuViewFrame;;
   }
    completion:^(BOOL finished)
   {

   }];

我想要添加一个动画,以便UIView在它下降之前到达顶部时浮动一点,即类似于是否有人在空中跳跃 - 当它们第一次跳跃时,它们快速射击,但随后重力当它们到达跳跃的顶部时逐渐减慢它们,并最终将它们推回地面。有谁知道如何做到这一点?

1 个答案:

答案 0 :(得分:2)

尝试使用此代码。每次高度减半时,这将使您的视图反弹三次。您可以添加更多反弹。

CGFloat offset = 200.0;

CGRect originalFrame = self.menusView.frame;

[UIView animateWithDuration:1.0 animations:^{
    CGRect frame = self.runnerAlertView.frame;
    frame.origin.y = frame.origin.y - offset;
    self.menusView.frame = frame;
} completion:^(BOOL finished){
    [UIView animateWithDuration:1.0 animations:^{

        self.menusView.frame = originalFrame;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:1.0 animations:^{
            CGRect frame = self.menusView.frame;
            frame.origin.y = frame.origin.y - 0.5 *offset;
            self.menusView.frame = frame;
        } completion:^(BOOL finished){
            [UIView animateWithDuration:1.0 animations:^{

                self.menusView.frame = originalFrame;
            } completion:^(BOOL finished) {
                [UIView animateWithDuration:1.0 animations:^{
                    CGRect frame = self.runnerAlertView.frame;
                    frame.origin.y = frame.origin.y - 0.25 * offset;
                    self.menusView.frame = frame;
                } completion:^(BOOL finished){
                    [UIView animateWithDuration:1.0 animations:^{

                        self.menusView.frame = originalFrame;
                    }];
            }];
        }];
        }];
    }];
}];