0

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

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

   }];

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

4

1 回答 1

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;
                    }];
            }];
        }];
        }];
    }];
}];
于 2013-10-27T00:25:38.543 回答