简体   繁体   English

UIImageView“反弹”动画

[英]UIImageView “bounce in” animation

Can anyone guide me in the right direction on figuring out how to animate a UIImageView like so: 谁能在正确的方向上指导我弄清楚如何为UIImageView设置动画,如下所示:

On the initial load of the app, a UIImageView will come in from the top of the screen and then bounce (up and down) into the bottom a couple times before settling at the bottom. 在应用程序初始加载时,UIImageView将从屏幕顶部进入,然后反弹(上下)几次进入底部,然后再稳定在底部。

I know how to animate it where it just moves along the Y axis, but how to do the slight bounce effect at the end? 我知道如何为它沿Y轴移动的位置设置动画,但是最后如何做轻微的弹跳效果呢?

Thanks! 谢谢!

MoveMe sample code from Apple demonstrate a bouncing animation. 苹果公司的MoveMe示例代码演示了一个反弹动画。 Check the method - (void)animatePlacardViewToCenter in MoveMeView class. 检查MoveMeView类中的方法- (void)animatePlacardViewToCenter It creates a bounceAnimation . 它创建一个bounceAnimation As you need bouncing only in y axis, it will be easier to implement than the sample. 由于只需要在y轴上弹跳,因此比示例更容易实现。

One way to achieve this (I've used this method with great success) is to use nested animations. 实现此目的的一种方法(我已经成功使用了此方法)是使用嵌套动画。 You could take advantage of the UIView + (void)animateWithDuration:animations method. 您可以利用UIView +(void)animateWithDuration:animations方法。

Here's the pseudo for it: 这是它的

Animation{
    //Fall to the bottom along the y axis
    [self doFallToBottom];
    onCompletion:
    {
          Animation{
             //Hits the bottom.  Bounce up a bit along the y axis (maybe 100 pixels or so)
             [self bounceUp:100];
             onCompletion:
             {
                //Fall back down to the bottom along the y axis
                [self doFallToBottom];
             }
          }       
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM