4

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's not working correctly. It becomes wider at the end of the animation then it goes back to normal. I want the width to bounce to a lesser value than 1.0, not more than 1.0.

Eric
  • 3,811
  • 5
  • 15
  • 18
  • That isn't the bounce animation I'm looking for. – Eric May 07 '15 at 00:34
  • The animation is working just as it's supposed to. It's just not what you **want**. You'll have to add a simple `animateWithDuration:` block in the completion block of the current code. **Or** as muku has pointed out, use `UIDynamicAnimator`. – n00bProgrammer May 15 '15 at 01:54

2 Answers2

10

ust for future code reuse and keeping code clean

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;                            
        }];
    }];
}];
Vijay yadav
  • 1,220
  • 8
  • 17
2

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

How to create a UIView bounce animation?

Community
  • 1
  • 1
Mukesh
  • 3,680
  • 1
  • 15
  • 32