如何更改 UIWindow 中的 RootViewController 并将其交叉溶解到新的根目录?
问问题
1257 次
2 回答
4
我建议transitionFromView
在UIView
. 例如,您可以使用以下代码来处理您的转换:
- (void)transitionToViewController:(UIViewController *)viewController
withTransition:(UIViewAnimationOptions)transition
{
[UIView transitionFromView:self.window.rootViewController.view
toView:viewController.view
duration:0.65f
options: UIViewAnimationOptionTransitionCrossDissolve
completion:^(BOOL finished){
self.window.rootViewController = viewController;
}];
}
您可以在此处找到此方法的参考文档。
于 2012-09-23T22:01:47.393 回答
0
让我们看一下我的示例以了解如何切换 rootviewcontroller。
- (void)showTutorialsScreen:(BOOL)animated
{
NUDTutorialsViewController *tutorialsVC = [[NUDTutorialsViewController alloc] initWithNibName:NSStringFromClass([NUDTutorialsViewController class]) bundle:nil];
UINavigationController *tutorialsNavController = [[UINavigationController alloc] initWithRootViewController:tutorialsVC];
[self switchRootViewController:tutorialsNavController animated:animated completion:nil];
}
- (void)showLoadingScreen:(BOOL)animated
{
NUDLoadingViewController *loadingVC = [[NUDLoadingViewController alloc] initWithNibName:NSStringFromClass([NUDLoadingViewController class]) bundle:nil];
[self switchRootViewController:loadingVC animated:animated completion:nil];
}
- (void)showMainScreen:(BOOL)animated
{
NUDMainViewController *mainVC = [[NUDMainViewController alloc] initWithNibName:NSStringFromClass([NUDMainViewController class]) bundle:nil];
UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:mainVC];
[self switchRootViewController:mainNavController animated:animated completion:nil];
}
- (void)switchRootViewController:(UIViewController *)aRootViewController animated:(BOOL)animated completion:(void(^)())completion
{
if (animated) {
[UIView transitionWithView:self.window duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
self.window.rootViewController = aRootViewController;
[UIView setAnimationsEnabled:oldState];
} completion:^(BOOL finished) {
if (completion) completion();
}];
}
else {
self.window.rootViewController = aRootViewController;
if (completion) completion();
}
}
于 2014-06-24T02:24:04.147 回答