【发布时间】:2012-10-07 08:58:24
【问题描述】:
我的应用中有一个自定义拆分视图控制器,带有一个主控制器和一个详细控制器。
- (id)initWithMasterController:(UIViewController*)aMasterController
detailedController:(UIViewController*)aDetailedController;
主控制器和细节控制器提供的控制器是UINavigationController。
作为我的应用程序的一部分,方向处理有两种可能的情况:
- 当主控制器和细节控制器使用六种控制器组合时,应用程序支持所有方向。
- 当仅在详细信息控制器上存在 StudentDetailsViewController 时,只能支持两种可能的方向。 (风景)
当设备的方向发生变化时,iOS 6.0 以下的版本会发生以下情况
-
-shouldAutorotateToInterfaceOrientation:方法被调用。该方法的实现如下:在运行时,我通过相同的调用将请求转发到主控制器和细节控制器。- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { BOOL res = [masterController shouldAutorotateToInterfaceOrientation:interfaceOrientation] && [detailedController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; return res; } -
主控制器的
-shouldAutorotateToInterfaceOrientation将返回TRUE。 StudentViewController 中方法的实现如下。- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (IS_IPAD) ? UIInterfaceOrientationIsLandscape(interfaceOrientation) : UIInterfaceOrientationIsPortrait(interfaceOrientation); }
获取有关要更改的新方向的信息的能力有助于我决定是否应启用旋转。
使用 iOS 6.0:
当设备的方向改变时,iOS 6.0 版本会发生以下情况
-
分割视图控制器的
-shouldAutorotate方法被调用。它的实现如下- (BOOL)shouldAutorotate { BOOL res = [masterController shouldAutorotate] && [detailedController shouldAutorotate]; return res; } -
detailedController 的 shouldAutorotate 调用 navigationController。 StudentsController 中自动旋转功能的实现:
- (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight); }
但在 iOS 6.0 中,我无法控制方向。即使调用了supportedInterfaceOrientations方法,但是当调用StudentDetailsController的shouldAutorotate方法时,从detailsController的shouldAutorotate方法中,shouldAutorotateMethod不服从supportedInterfaceOrientations方法中提到的选项。
更新:
我阅读了文档,document 中提供了以下注释。
有时您可能希望动态禁用自动旋转。为了 例如,当您想抑制旋转时,您可能会这样做 完全在短时间内。您必须暂时禁用 方向改变你想手动控制的位置 状态栏(例如当您调用 setStatusBarOrientation:animated: 方法)。
如果您想暂时禁用自动旋转,请避免 操纵方向蒙版来做到这一点。相反,覆盖 最顶层视图控制器上的 shouldAutorotate 方法。这种方法是 在执行任何自转之前调用。如果返回 NO,则 旋转被抑制。
是否可以暂时禁用基于当前方向的自动旋转?
【问题讨论】:
-
无法正确格式化代码..
-
问题解决了吗?我有同样的问题,不知道如何为 ios5 和 6 处理这个问题
-
不,我还没有解决它..
标签: objective-c ios6 uiinterfaceorientation