有几种方法可以做到这一点。有些比其他更好,但主要取决于具体情况的需要。
- 替换您在循环过程中提到的
rootViewController
。
- 始终使用
UISplitViewController
并使用segue
与replace
替换纵向和横向之间旋转时的detailViewController
。
- 使用/做增加了一个自定义的容器视图控制器/使用
addChildViewController:
和removeFromParentViewController:
消除了对旋转相应的视图控制器
选择3
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.childViewControllers[0].view removeFromSuperView];
[self.childViewControllers[0] removeFromParentViewController];
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
[self addChildViewController:portraitVC];
[self.view addSubview:portraitVC.view];
} else {
[self addChildViewController:landscapeVC];
[self.view addSubview:landscapeVC.view];
}
}
极其原油例如从你已经什么说,我猜想选项3将是最合适的。尽管如此,我并不完全相信你需要切换视图控制器,但我不熟悉ECSlidingViewController
,它提供了什么,所以我不能确定。
来源
2013-02-19 15:41:38
DBD
感谢您的回复。我想在检测到旋转时重置rootViewController。你知道我能做到吗?当我尝试它时,它似乎做了一些奇怪的分层和旋转.... – 2013-02-19 16:14:58
问题是,我的ECSlidingViewController实现的主视图控制器需要扩展一个特定的子类,这将在使用UISplitViewController时发生冲突。 – 2013-02-19 16:19:55
我最终将我的实现更改为上面提出的解决方案3,这解决了问题。 – 2013-02-19 17:01:28