Erik Sapir
Erik Sapir

Reputation: 24727

Showing UIView with bouncy animation

I want to create a bouncy animation like in the Skitch application - when i press a button, a subview (simple view with several buttons) will appear from the side and will bounce a bit until it stops.

I can't find any standard animation that does that, so how i can implement this animation?

Upvotes: 0

Views: 1110

Answers (3)

Harjot Singh
Harjot Singh

Reputation: 6927

Use the UIView method, If you want bouncing effect. Then you need to nested the animation process and give the frame as needed for that view. Here's the example:

CGRect frameOnStart = CGRectMake(200,200 ,60 ,60); //On start show small view

CGRect frameOnAnimate = CGRectMake(80,80 ,150 , 150); //while animate show large view

CGRect frameAfterAnimate = CGRectMake(100,100,120 ,120);  //after animate large take it back to original frame. SO it loos like bouncing animation

// Whenever you want, call this :
[UIView animateWithDuration:0.5
                      delay:0
     usingSpringWithDamping:0.5
      initialSpringVelocity:0
                    options:UIViewAnimationOptionCurveLinear
                 animations:^{

                     // Set your on Animate position here
                     view.frame = frameOnAnimate;
                 }
                 completion:^(BOOL finished) {
                     [UIView animateWithDuration:0.5
                                           delay:0
                          usingSpringWithDamping:0.5
                           initialSpringVelocity:0
                                         options:UIViewAnimationOptionCurveLinear
                                      animations:^{

                                          // Set your final view position here
                                          view.frame = frameAfterAnimate;
                                      }
                                      completion:^(BOOL finished) {


                                      }]

                 }];

Thanks.

Upvotes: 1

rdurand
rdurand

Reputation: 7410

You can try this :

// Hide your view by setting its position to outside of the bounds of the screen

// Whenever you want, call this :
[UIView animateWithDuration:0.5
                      delay:0
     usingSpringWithDamping:0.5
      initialSpringVelocity:0
                    options:UIViewAnimationOptionCurveLinear
                 animations:^{

                     // Set your final view position here

                 }
                 completion:^(BOOL finished) {


                 }];

This method is the same as the usual animateWithDuration: but it introduces a spring animation.

Upvotes: 4

PiotrDomo
PiotrDomo

Reputation: 1045

Use UIView method:

+ (void)animateWithDuration:(NSTimeInterval)duration 
                      delay:(NSTimeInterval)delay 
     usingSpringWithDamping:(CGFloat)dampingRatio 
      initialSpringVelocity:(CGFloat)velocity 
                    options:(UIViewAnimationOptions)options 
                 animations:(void (^)(void))animations 
                 completion:(void (^)(BOOL finished))completion

This will do what you want

Upvotes: 2

Related Questions