如何避免ViewController打开时Orientation错误
最近在一个iPad项目上要做一个BeginnerGuide,我的设计是将其做在help里,在第一次运行程序时显示此help,否则在需要了解帮助信息时,可以点击help按钮打开此BeginnerGuide。
我的结构是一个基于SplitViewController的Master-Detail结构,在第一次运行时,在Master的ViewWillAppear中通过performSegueWithIdentifier弹出此help窗口,其它情况下通过在点击Master中的help按钮弹出。之所以在ViewWillAppear中弹出而不是ViewDidAppear,是由于不想在显示BeginnerGuide之前,让用户看到主界面,那样就不叫BeginnerGuide了。
这里的问题是,在ViewWillAppear中弹出的窗口初始时总是Portrait模式,而不管设备所处模式是什么。但是打开之后,旋转设备,窗口则可以根据实际的模式调整过来。如果在父窗口的ViewWillAppear或新弹出的ViewController中的ViewDidLoad中运行如下代码:
- (void)viewWillAppear: (BOOL)animated { [super viewWillAppear:animated]; if (freshInstall) { dispatch_async(dispatch_get_main_queue(),^{ [self performSegueWithIdentifier: @"firstRun" sender: self]; }); }}