Ben Packard
Ben Packard

Reputation: 26476

Animation Block - Completion fires immediately

Why does the following code log 'Done' as soon as it is fired?

[UIView animateWithDuration:0.3 
                 animations:^{
                        NSLog(@"Start");
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"done");
                 }
 ];

Upvotes: 2

Views: 1641

Answers (2)

Christian
Christian

Reputation: 1714

Because you aren't animating anything. If you change the value of some UIView in your animation block, you will correctly see "done" outputted after the 0.3 second delay.

I tested with a 5 second delay using exactly your code, only adding in something to animate to confirm.

Upvotes: 3

W Dyson
W Dyson

Reputation: 4634

Because you're not actually animating anything (a NSLog cannot be animated). You need to animate an object or else the completion block will be called straight away. The 0.3 second duration will be ignored if there is nothing being animated.

Upvotes: 9

Related Questions