How to add bounce animation to animateWithDuration?

I have a simple animation that I execute in my scroll delegate 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 my finger, my homeLabel goes on top and I want to add its rebound animation to the shortcut, so when it comes from above, instead of coming smoothly, it will have a good rebound ... How do I do this? thanksss

+5
source share
2 answers

You can use the animated function usingSpringWithDamping .

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

Setting up Spring Damping and Initial Spring Velocity can give you the desired effect.

+17
source

One good solution is to create a custom level for your view that overrides the addAnimation:forKey: method to enable a custom synchronization function.

This answer is specific to how to do this.

Another option is to look at the keyframe animation. This question covers this approach very well.

0
source

Source: https://habr.com/ru/post/1211005/


All Articles