Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get animation end notification

I want to do some action once animation ended.

[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 have done animation like above, How to find out animation ended, so that I can do my action after that.

like image 694
Newbee Avatar asked Dec 01 '22 21:12

Newbee


2 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
    }];
like image 96
andreamazz Avatar answered Dec 16 '22 21:12

andreamazz


Add this to your animation:

[UIView setAnimationDidStopSelector:@selector(myAnimationEnded)];
[UIView setAnimationDelegate:self];

and this method will tell you when it stops;

- (void)myAnimationEnded{
     NSLog(@"animation ended");
}
like image 29
John Smith Avatar answered Dec 16 '22 22:12

John Smith