After the animation is completed, you need to call some methods

In my iPhone app

I do certain animations. as

[UIView beginAnimations:@"stalk" context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationBeginsFromCurrentState:YES]; self.frame=originalSelf; [UIView commitAnimations]; 

After completing this animation, I want tocall some methods ...

I know something like an animation block or

DidStopAnimation Notification

How do I do this .... Thanks ..

+6
source share
3 answers

In iOS 4 and later, it is recommended to use blocks for this purpose:

 [UIView animateWithDuration:1 animations:^{ self.frame=originalSelf;} completion:^(BOOL finished){ //My method call; } ]; 
+11
source

Try using

 [UIView beginAnimations:@"stalk" context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationBeginsFromCurrentState:YES]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(afterAnimationStops)] self.frame=originalSelf; [UIView commitAnimations]; 

And then you can implement the method

 -(void)afterAnimationStops{ } 
+5
source

Use this:

 animateWithDuration:animations:completion: 

Here's more info: http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html

Here is an example:

 [UIView animateWithDuration:1.0 animations:^{self.frame=originalSelf;} completion:^(BOOL finished){/*have your completion code here*/}]; 
+2
source

Source: https://habr.com/ru/post/905186/


All Articles