supportedInterfaceOrientations方法不适用于iOS 6 UIViewController

Che*_*kie 11 orientation uiviewcontroller ios6

iOS 5中,我的应用程序使用该方法来改变我的方向:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)

iOS 6中我认为我应该这样做,但它什么都不做!我的应用程序旋转不是我想要的方式.

- (BOOL) shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight;
}
Run Code Online (Sandbox Code Playgroud)

Che*_*kie 28

这就是我添加我的方式viewController.

我替换了这行代码:

[window addSubview:viewController.view];
Run Code Online (Sandbox Code Playgroud)

通过这一行:

[window setRootViewController:viewController];
Run Code Online (Sandbox Code Playgroud)


Dan*_*iel 15

当设备更改方向时,在iOS 6中,系统会询问应用程序支持的方向.应用程序将返回它接受的多个方向.

应用程序如何确定其方向?

  1. 首先,应用程序检查它的info.plist方向(这对于确定用于启动的方向非常重要.
  2. 其次,它询问它的应用程序委托它的方向,这可以通过该-(NSUInteger)application:supportedInterfaceOrientationsForWindow:方法指定.这有效地覆盖了info.plist设置,这个实现是可选的.默认情况下,iPad应用程序可以向各个方向定位,而iPhone则可以完全颠倒.
  3. 最后,应用程序委托查询它的最顶层视图控制器,它可以是a UINavigationControllerUIViewController...等,然后它指定如何呈现以及是否要自动旋转.这些UIViewControllers可以使用shouldAutorotate:supportedInterfaceOrientations方法告诉应用程序委托如何呈现它.

您必须确保设置窗口的根视图控制器.

此外,如果您以全屏显示任何其他视图控制器,例如模态视图控制器,则负责确定方向更改的人员.