dehlen
dehlen

Reputation: 7389

UIViewAnimation bounce after setting frame

i got a UIImageView which should slide from the top into the view and then when it stops it should make a bounce animation.

I am animating the y.position change like this:

     [UIView animateWithDuration:1.3
                                   delay:0.0
                                 options:UIViewAnimationOptionCurveEaseIn
                              animations:^{
                  [grassView setFrame:CGRectMake(grassView.frame.origin.x, 425, grassView.frame.size.width, grassView.frame.size.height)];
                  [headlineView setAlpha:1.0];
                  [self.loginButton setAlpha:1.0];
             // [textView setAlpha:1.0];
             [textView setFrame:CGRectMake(textView.frame.origin.x, -136, textView.frame.size.width, textView.frame.size.height)];

         }

                              completion:^(BOOL finished) {
             self.usernameField.placeholder = NSLocalizedString(@"username", nil);
             self.passwordField.placeholder = NSLocalizedString(@"password", nil);
}];

Don't worry about setting the origin.y coordinate to -136. My image view lays outside the screen at -460 because its height is 450. But when sliding the imageview into the screen i don't want to show the whole image which is why it does not animate to a y.position >= 0. But this part works just fine. My imageview is shown at the correct position where i want it to be. Now i need advise on how to let the imageview bounce when the position was changed. I already tried some CABasicAnimation but it didn't looked like i wanted it to be. Also when i call the method to let the imageview bounce in the completion block of my UIViewAnimation the bouncing effect starts to late.

Does somebody has a hint or idea for me how to get the imageview bounce after the frame was set ?

Upvotes: 0

Views: 449

Answers (1)

robert
robert

Reputation: 2842

since iOS7 you can use

[UIView animateWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> usingSpringWithDamping:<#(CGFloat)#> initialSpringVelocity:<#(CGFloat)#> options:<#(UIViewAnimationOptions)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#> ]

just play around with the damping value and the initial velocity.

Upvotes: 2

Related Questions