Skip to content

Instantly share code, notes, and snippets.

@sbrocket
Created June 10, 2011 13:53
Show Gist options
  • Save sbrocket/1018866 to your computer and use it in GitHub Desktop.
Save sbrocket/1018866 to your computer and use it in GitHub Desktop.
- (void)transitionToNewRootViewController:(UIViewController *)newRootVC animated:(BOOL)animated moveToLeft:(BOOL)moveToLeft {
UIViewController *rootVC = self.window.rootViewController;
if (rootVC == newRootVC) {
return;
}
CGFloat direction = (moveToLeft) ? 1 : -1;
CGRect initialFromFrame = rootVC.view.frame;
CGRect initialToFrame = initialFromFrame;
initialToFrame.origin.x += direction * initialFromFrame.size.width;
CGRect finalFromFrame = initialFromFrame;
finalFromFrame.origin.x -= direction * initialFromFrame.size.width;
CGRect finalToFrame = initialFromFrame;
newRootVC.view.frame = initialToFrame;
[self.window addSubview:newRootVC.view];
[UIView animateWithDuration:(animated) ? 0.3 : 0.0 animations:^{
rootVC.view.frame = finalFromFrame;
newRootVC.view.frame = finalToFrame;
} completion:^(BOOL finished) {
[rootVC.view removeFromSuperview];
self.window.rootViewController = toVC;
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment