I want to do some action after the animation is complete.
[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.80f]; self.view.transform = CGAffineTransformMakeTranslation( self.view.frame.origin.x, 480.0f + (self.view.frame.size.height/2) // move the whole view offscreen ); [self.view setAlpha:0]; [UIView commitAnimations];
I made an animation as shown above. How to find out that the animation is complete so that I can do my action after that.
Use this:
[UIView animateWithDuration:0.80f animations:^{ self.view.transform = CGAffineTransformMakeTranslation( self.view.frame.origin.x, 480.0f + (self.view.frame.size.height/2) // move the whole view offscreen ); [self.view setAlpha:0]; } completion:^(BOOL finished){ // your code }];
Add this to your animation:
[UIView setAnimationDidStopSelector:@selector(myAnimationEnded)]; [UIView setAnimationDelegate:self];
and this method will tell you when it will stop;
- (void)myAnimationEnded{ NSLog(@"animation ended"); }
Use the class method UIView -animateWithDuration:animations:completion:
UIView
-animateWithDuration:animations:completion:
[UIView animateWithDuration:0.8 animations:^{ CGAffineTransformMakeTranslation( self.view.frame.origin.x, 480.0f + (self.view.frame.size.height/2) // move the whole view offscreen ); [self.view setAlpha:0]; } completion:^(BOOL finished) { //this block is called when the animation is over }];
Enter the code after [UIView commitAnimations]; . Animation stays between beginAnimations and commitAnimations .
[UIView commitAnimations];
beginAnimations
commitAnimations
Not that setAnimationDelegate
setAnimationDelegate
Using this method is not recommended in iOS 4.0 and later. If you use block-based animation methods, you can include your start and end code for your delegates directly inside your block.