Search code examples
iphonecocoa-touchioscore-animation

Why do I see jerky animation when using this UIView animation block?


I have a a tab bar that is made in the application delegate. By calling an action form a button click from one of the views loaded from the tab bar, I open the help screen but there is a jerking motion after loading.

forgive me for speaking informally..I have been picking my brain for the past few hours trying to figure this out..

-(void)flipToHelp {
 HelpViewController *helpVariable = [[HelpViewController alloc] initWithNibName:@"HelpView" bundle:nil];
 [self setHelpViewController:helpVariable];
 [UIView beginAnimations:@"flipview" context:nil]; 
 [UIView setAnimationDuration:0.5];
 [UIView setAnimationCurve:UIViewAnimationCurveLinear];
 [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
 forView:_window cache:YES];

[_window removeFromSuperview];
[helpVariable release];
self.window.rootViewController = self.HelpViewController;
[UIView commitAnimations];
}

Solution

  • Just to reiterate from the comment thread, you shouldn't be removing the window from its superview (it doesn't technically have a superview, so it's probably causing problems). And setting the window's rootViewController property should swap out the view hierarchies, Apparently the jerkiness comes from changing the window's rootViewController property, so maybe the solution is to avoid using that property. Here's what I think should be enough to accomplish this:

    -(void)flipToHelp {
         HelpViewController *helpVariable = [[HelpViewController alloc] initWithNibName:@"HelpView" bundle:nil];
         [UIView beginAnimations:@"flipview" context:nil]; 
         [UIView setAnimationDuration:0.5];
         [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:_window cache:YES];
        [self.tabBarController removeFromSuperview];
        [_window addSubview:helpVariable];
        [UIView commitAnimations];
    }