【发布时间】:2013-08-07 01:06:56
【问题描述】:
我有一个 UINavigationController 作为我的 UIWindow 的 rootViewController 和一个仅支持纵向方向的 UIViewController (ControllerA) 添加到 UINavigationController 作为其 rootViewController。
稍后,我将 UINavigationController's rootViewController 替换为新的 UIViewController (ControllerB)。 ControllerB 支持纵向和横向。我希望我的初始屏幕 (ControllerA) 只能在纵向模式下工作,而应用程序的其余部分可以同时支持纵向和横向。
[self.navigationController setViewControllers:@[viewControllerB] animated:NO];
| UINavigationController launches:
| ----ControllerA (rootViewController): Portrait only
| ----ControllerB (rootViewController): Portrait and Landscape supported
如果我在未由 ControllerA 处理的横向模式下启动我的应用程序,然后移动到 ControllerB,我的内容(+状态栏)仍然是纵向模式。如果此时我手动旋转设备,我就有了正确的内容布局。
如何让 ControllerB 在设备的方向上呈现自身?
这是我从 ControllerA 和 ControllerB viewWillAppear 方法看到的:
navigationController orientation: UIInterfaceOrientationPortrait
UIViewController interfaceOrientation: UIInterfaceOrientationPortrait
<!-----------!!two values are different!!------------------>
[[UIDevice currentDevice] orientation]: UIDeviceOrientationLandscapeLeft
[[UIApplication sharedApplication] statusBarOrientation]: UIInterfaceOrientationPortrait
Phone is physically held in Landscape at this point in time.
【问题讨论】:
-
根据我的经验,[[UIApplication sharedApplication] statusBarOrientation]: UIInterfaceOrientationPortrait 是确定的并且永远是正确的。据我所知,[UIDevice currentDevice] 方向不可靠。
-
为什么当 ControllerB 设置为 NavBar 的根但我保持横向时,statusBar 报告处于纵向模式?
-
这是一个非常好的问题!
-
一种流行的解决方法似乎是转换视图:stackoverflow.com/questions/13002477/…,但我不确定是否有更好、更少被黑的解决方案。
-
我一直在仔细研究这个问题。据我所知,没有办法确定方向应该是什么并在那里旋转。
标签: ios uiviewcontroller