【问题标题】:Is There Anyway I can make my image jump then fall back down无论如何我可以让我的形象跳跃然后回落
【发布时间】:2014-04-13 16:44:49
【问题描述】:

我希望我的图像跳上 7 条 y 轴或其他东西,但我希望他回落。有什么帮助吗?

这是我的代码:

CGRect frame = Guy.frame;
frame.origin.x = frame.origin.x - 0;
frame.origin.y = frame.origin.y - 7;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.60];
Guy.frame = frame;
[UIView commitAnimations];

【问题讨论】:

  • 您应该查看 UIDynamicAnimator 和相关的类来执行此操作。如果您对此一无所知,那么我会查看 WWDC 2013 的视频(“UIKit Dynamics 入门”)。
  • 来自@rdelmar 的一个很好的...除了他的评论,我想指出一个相同的教程..teehanlax.com/blog/introduction-to-uikit-dynamics

标签: ios objective-c gravity


【解决方案1】:

试试这个:

CGRect frame = Guy.frame;
[UIView animateWithDuration:0.6 delay: 0 options:UIViewAnimationCurveEaseInOut  animations: ^{
    Guy.frame = CGRectMake(frame.origin.x, frame.origin.y - 7,
                           frame.size.width, frame.size.height);
} completion: ^(BOOL finished) {
    if (finished) {
        [UIView animateWithDuration:0.6 delay: 0 options:UIViewAnimationCurveEaseInOut  animations: ^{
            Guy.frame = CGRectMake(frame.origin.x, frame.origin.y + 7,
                                   frame.size.width, frame.size.height);
        }];
    }
}];

【讨论】:

  • 既然你的反对者没有礼貌地解释原因,我会的。您的代码没有回答问题。问题询问如何使图像向上然后再向下移动。
  • 这看起来更好,但您可能希望指定每个方向的动画曲线以使其更好看。
【解决方案2】:
[UIView animateWithDuration:1.0
    delay: 0.0
    animations:^{
         image.frame = CGRectMake(image.frame.origin.x, image.frame.origin.y-7, image.frame.size.width, image.frame.size.height);
    }
    completion:^(BOOL finished){
        // move it ba
        [UIView animateWithDuration:1.0
             delay: 1.0
             options:UIViewAnimationOptionCurveEaseOut
             animations:^{
                image.frame = CGRectMake(image.frame.origin.x, image.frame.origin.y+7, image.frame.size.width, image.frame.size.height);
             }
             completion:nil];
    }];

【讨论】:

  • 第二个动画似乎不适合这个问题。
【解决方案3】:
[UIView animateWithDuration:.5 delay:0.0
                    options:UIViewAnimationOptionCurveEaseIn
                 animations:^{
                     CGRect f = imageview.frame;
                     f.origin.y -= 40;
                     imageview.frame = f;
                 }
                 completion:nil];
if (imageview.frame.origin.y) {

 [UIView animateWithDuration:.6 delay:0.1
                                         options:UIViewAnimationOptionCurveEaseIn
                                      animations:^{
                                          CGRect f = imageview.frame;
                                          f.origin.y += 80;
                                          imageview.frame = f;
                                      }
                  completion:nil];}

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    相关资源
    最近更新 更多