0

I'm trying to wait for an animation to finish before starting another task. I looked at different methods but using CATransactions seems to be the most used method to do this. Somehow, my CATransaction Completionblock triggers immediately after the animation starts, not after it finishes.

Here's my code:

[CATransaction begin];
[CATransaction setCompletionBlock: ^{
    NSLog(@"Animation ends");
}];
NSLog(@"Animation begins");
[tableView setEditing:NO animated:YES];
[CATransaction commit];

When looking at the console I get this:

2014-03-17 15:44:12.995 BarTap[89934:70b] Animation begins
2014-03-17 15:44:12.997 BarTap[89934:70b] Animation ends

So appearently the Completionblock starts 0.002 seconds after the animation begins, but the animation definitely takes longer than that. Could anyone help me? Thanks!

Luca K
  • 1
  • 1

1 Answers1

0

Animation completion triggers immediately because there are no tasks for animation in your code. CAAnimation effects to CALayer properties and it finishes immediately if there no changes in animatable properties.

Try this:

[UIView animateWithDuration:timeInterval animations:^{
    [tableView setEditing:NO animated:NO];
} completion:^(BOOL finished) {
    // Perform tasks after animation completion here
}];
Vlad Papko
  • 12,848
  • 4
  • 38
  • 52