ios - UIView动画: simulating velocity

标签 ios iphone cocoa-touch core-animation uiviewanimation

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

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

   }];

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

最佳答案

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

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

关于ios - UIView动画: simulating velocity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19613139/

相关文章:

ios - 如何在单独的动画中将 CGAffineTransform 链接在一起?

ios - Theos for ARM64 无法正常工作(Clang 抛出错误)

ios - 适用于 iOS 的 Google Drive SDK 示例无法正常工作

objective-c - didRotateFromInterfaceOrientation : is not called for controller which presented modal controller on iOS 5

objective-c - iOS 6 中用于完成 block 的 dispatch_get_current_queue() 的替代方案?

ios - 无法在 subview Controller 中隐藏选项卡栏

ios - 如何在 Xcode 7 中为 Homekit 添加 app_name.entitlements 文件

iphone - 在尝试将 ios 应用程序发布到应用程序商店之前需要完成的事情

iphone - DDXML 解析器中的内存泄漏

iphone - 核心数据关系错误(不是延迟加载)。关系消失