codeman
codeman

Reputation: 9038

UIImageView "bounce in" animation

Can anyone guide me in the right direction on figuring out how to animate a UIImageView like so:

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.

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?

Thanks!

Upvotes: 0

Views: 1180

Answers (2)

Jeremy
Jeremy

Reputation: 9030

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.

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

Upvotes: 0

taskinoor
taskinoor

Reputation: 46037

MoveMe sample code from Apple demonstrate a bouncing animation. Check the method - (void)animatePlacardViewToCenter in MoveMeView class. It creates a bounceAnimation. As you need bouncing only in y axis, it will be easier to implement than the sample.

Upvotes: 1

Related Questions