Wait for Animation to finish in iOS?

animation, ios, objective-c

Solution

When you are not the author of the animation, you can get a callback when the animation ends by using a transaction completion block:

[CATransaction setCompletionBlock:^{
     // doSomethingElse
}];
// doSomething

Problem

I want to execute doSomethingElse after the animation is finished. Another constraint is that the animation code can be of different duration. How can I do that? thanks! ``` -(void) doAnimationThenSomethingElse { [self doAnimation]; [self doSomethingElse]; } ``` This for example doesn't work: ``` animationDuration = 1; [UIView animateWithDuration:animationDuration animations:^{ [self doAnimation]; } completion:^(BOOL finished) { [self doSomethingElse]; } ]; ```

Original source