我正在通过按下一个连接到我想要更改为的视图控制器的自定义segue的按钮来更改根视图控制器.自定义segue看起来像:
- (void)perform{ UIViewController *source = (UIViewController *)self.sourceViewController; source.view.window.rootViewController = self.destinationViewController; }
但这只会立即更改根视图控制器.我希望控制器在旧控制器之上淡出.
解决方法
常见的方法是:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"YourSBName" bundle:nil]; UIViewController *vc = [sb instantiateInitialViewController];// Or any VC with Id DictateITAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; appDelegate.window.rootViewController = vc; // PLEASE READ NOTE ABOUT THIS LINE [UIView transitionWithView:appDelegate.window duration:INTERVAL_DURATION options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ appDelegate.window.rootViewController = vc; } completion:nil];
现在有几点说明:
appDelegate.window.rootViewController = vc; // PLEASE READ NOTE ABOUT THIS LINE
您实例化的新视图控制器将以默认方向显示,即纵向.因此,如果您在横向中执行此操作,则新视图控制器将显示为纵向,然后转为横向.这条线为我解决了这个问题.