【问题标题】:UIView animation: simulating velocityUIView 动画:模拟速度
【发布时间】:2013-10-26 23:42:11
【问题描述】:

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

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

   }];

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

【问题讨论】:

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


    【解决方案1】:

    试试这个代码。这将使您的视野反弹三次,每次您的身高减少一半。您可以添加更多退回邮件。

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

    【讨论】:

    • +1。感谢那。它确实做到了,我正在以与您相同的方式嵌套 UIViewAnimations 并且它从来没有完全正确。我想知道我是否可能需要使用核心动画。
    猜你喜欢
    • 2017-10-23
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多