How to get an animation notification

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.

+4
source share
5 answers

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 }]; 
+7
source

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"); } 
+7
source

Use the class method 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 }]; 
+4
source

Enter the code after [UIView commitAnimations]; . Animation stays between beginAnimations and commitAnimations .

0
source

Not that 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.

0
source

All Articles