How to add a bounce effect to a UIViewWithDuration animation

I am trying to add a bounce effect to the animation below. Here is my code:

[UIView animateWithDuration:1.0
                       delay:.0
      usingSpringWithDamping:0.5
       initialSpringVelocity:2.0
                     options:UIViewAnimationOptionCurveEaseOut
                  animations:^{
                      // Coming from a value of CGAffineTransformMakeScale(0.001, 1.0)
                      self.myView.transform = CGAffineTransformMakeScale(1.0, 1.0);
                  }completion:nil
          ];

      

It is not working properly. It gets wider at the end of the animation, then it returns to normal. I want the width to bounce down to less than 1.0, no more than 1.0.

+3


source to share


2 answers


ust for code reuse and code saving



popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);

[self.view addSubview:popUp];

[UIView animateWithDuration:0.3/1.5 animations:^{
    popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished) {
    [UIView animateWithDuration:0.3/2 animations:^{
        popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3/2 animations:^{
            popUp.transform = CGAffineTransformIdentity;                            
        }];
    }];
}];

      

+7


source


Detailed explanation of UIView bounce animation is given in this post, both UIDynamicAnimator and spring Animation



How do I create a UIView bounce animation?

+2


source







All Articles