Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add bounce animation to animateWithDuration?

I have a simple animation that im performing in my scroll view delegate method scrollViewDidEndDragging.

It looks like this:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {

    NSLog(@"finger was lifted");

    [UIView animateWithDuration:1.0
                     animations:^{
                         self.homeLabel.frame = self.view.frame;
                    }];
}

Using this animation after lifting the finger the my homeLabel is coming from top, and i want to add it a bounce animation to the label, so when it comes from top, instead of landing smoothly it will have a nice bounce...how can i DO THAT? thanksss

like image 605
nick shmick Avatar asked Jan 13 '15 16:01

nick shmick


People also ask

What is bounce animation?

Bounce Animation effect is used to move the element quick up, back, or away from a surface after hitting it.

What is usingSpringWithDamping?

usingSpringWithDamping : This controls the amount of damping, or reduction, applied to the animation as it approaches its final state. This parameter accepts values between 0.0 and 1.0 . Values closer to 0.0 create a bouncier animation, while values closer to 1.0 create a stiff-looking effect.


1 Answers

You can use the usingSpringWithDamping animation function.

[UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.2 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveLinear animations:^{
    self.homeLabel.frame = self.view.frame;
} completion:^(BOOL finished) {

}];

Adjusting the Spring Damping and Initial Spring Velocity can give you the effect you want.

like image 185
rakeshbs Avatar answered Sep 20 '22 20:09

rakeshbs