模态视图控制器力在iOS 6中的横向定向 [英] Modal View Controller force Landscape orientation in iOS 6

查看:131
本文介绍了模态视图控制器力在iOS 6中的横向定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a UITabBarController presented in Portrait mode. On one of the tabs I have a button that shows a UIViewController modally (A simple storyboard segue performs the action).

我想这个模态视图以风景模式,但我无法自动切换。

I want this modal view to be shown in Landscape mode, but I can't get it to turn automatically.

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

I have this in the modal views controller

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



我已将landscapeLeft添加到.plist支持的方向

I've added landscapeLeft to the .plist supported orientations (although this also allows the TabBar to be rotated which I don't want)

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

I've also added this to the ViewDidLoad of the modal view

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;

但我不能让它自己旋转。

but I just can't get it to rotate by itself.

感谢

EDIT ----

EDIT ----

似乎shouldAutoRotate

It seems shouldAutoRotate isn't even being called!

此外,我尝试检测方向,下面的代码总是显示2,不管方向如何!

Also, I'm trying to detect the orientation and this code below always shows 2, regardless of orientation!

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);
    }

EDIT 2 ---

EDIT 2 ---

我的坏。我想我应该提到我使用iOS 6.显示在iOS 5自动旋转。
shouldAutorotateToInterfaceOrientation已废弃,所以我需要阅读新的方法。

My bad. I guess I should have mentioned I was using iOS 6. The display rotates automatically on iOS 5. shouldAutorotateToInterfaceOrientation is deprecated so I need to read up on the new methods.

推荐答案


iOS 6.0发行说明

更多的责任转移到应用程序和应用程序委托。容器(例如UINavigationController)不咨询他们的孩子以确定他们是否应该自动旋转。

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. "

<$ c $

尝试了一个解决方案,使用了一个解决方案,使用了一个简单的方法来创建一个UIViewController。类别以添加方法到现有的UINavigationController类。

Tried a solution with using Category to add method to existing UINavigationController Class.

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

inside the shouldAutorotate method, you can call shouldAutorotate method in each view controller of self.viewControllers. In fact, you can pass to your child view controller.

这篇关于模态视图控制器力在iOS 6中的横向定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆