模态视图控制器强制iOS 6中的横向方向

我有一个以纵向模式呈现的UITabBarController.在其中一个选项卡上,我有一个按钮,以模态方式显示UIViewController(一个简单的故事板segue执行操作).

我希望这个模态视图以横向模式显示,但我不能让它自动转动.

我在模态视图控制器中有这个

- (BOOL)shouldAutorotatetoInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

我已将landscapeLeft添加到.plist支持的方向(虽然这也允许TabBar旋转,我不想要)

我还将它添加到模态视图的ViewDidLoad中

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;

但我不能让它自己旋转.

谢谢

编辑—-

似乎应该甚至没有调用自动旋转!

此外,我正在尝试检测方向,下面的代码总是显示2,无论方向如何!

if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait) {
        NSLog(@"1");
        self.hostView.frame = CGRectMake(0,60,200,255);
    } else {
        NSLog(@"2");
        self.hostView.frame = CGRectMake(0,45,480,255);
    }

编辑2 —

我的错.我想我应该提到我正在使用iOS 6.显示器在iOS 5上自动旋转.
shouldAutorotatetoInterfaceOrientation已弃用,因此我需要阅读新方法.

解决方法

iOS 6.0 Release Notes
“More responsibility is moving to the app and the app delegate. Now,iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. “

– (BOOL)不应该从IOS6调用任何Container(如UINavigationController)下的UIViewController的Uutorotate.

尝试使用Category将方法添加到现有UINavigationController类的解决方案.

在shouldAutorotate方法中,您可以在self.viewControllers的每个视图控制器中调用shouldAutorotate方法.实际上,您可以传递给您的子视图控制器.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...