Created
June 10, 2011 13:53
-
-
Save sbrocket/1018866 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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