Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an animation to the UIView in viewDidAppear?

I tried to add a animation to viewDidLoad and viewDidAppear, but it doesn't work:

- (void)viewDidAppear:(BOOL)animated{
 [UIView beginAnimations:@"transition" context:NULL];
 [UIView setAnimationTransition:110 forView:self.view cache:YES];
 [UIView commitAnimations];
}

Why?

like image 408
Flocked Avatar asked Feb 02 '10 23:02

Flocked


1 Answers

I had the same problem and I think I found the solution on this SO question.

When viewDidAppear gets called you still don't see anything on the screen (despite the name), but you are about to. You can then use a performSelector:withDelay or an NSTimer to launch your animation. The delay can just be 0.1 and your animation will play just when the screen appears.

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    NSLog(@"View did appear!");

    [self performSelector:@selector(animationCode) withObject:nil afterDelay:0.1f];
}

- (void)animationCode {
    // you animation code
}
like image 148
jackbravo Avatar answered Sep 24 '22 01:09

jackbravo