Darius Miliauskas
Darius Miliauskas

Reputation: 3504

Block-Based Animation does not Work: Animations and Completion Blocks are Executed Immediately (Without Duration)

I tried to animate some features of the UIView, anyway, I simplified everything to these code lines in "ViewController.m":

- (void)viewDidLoad {
    ...
    [UIView animateWithDuration: 5.0 animations:^{
            NSLog(@"animations");}
    completion:^(BOOL finished){NSLog(@"completion");}];
    }

Both blocks outputs immediately after loading despite the fact that animation should last five seconds.

Upvotes: 0

Views: 53

Answers (1)

Lucifer
Lucifer

Reputation: 480

You can't use block animations in viewDidLoad because the UIView you want to animate doesn't have superview at the present moment. Move the code to the viewDidAppear method.

Upvotes: 3

Related Questions