在iOS7中处理一个视图控制器的自动旋转 [英] Handling autorotation for one view controller in iOS7

查看:171
本文介绍了在iOS7中处理一个视图控制器的自动旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在SO上阅读了很多答案,但我似乎无法在iOS7上进行自动旋转。

I've read many answers on SO but I can't seem to get autorotation working on iOS7.

我只需要一个视图控制器来旋转,所以我我不想在我的Info.plist中设置旋转设置。

I only need one view controller to rotate, so I don't want to set rotation settings in my Info.plist.

据我了解Apple的文档,单个视图控制器可以覆盖全局旋转设置(来自Info.plist)通过简单地重写两个方法。 Info.plist设置为仅允许Portrait,我的视图控制器实现以下方法:

As I understand Apple's documentation, a single view controller can override global rotations settings (from Info.plist) by simply overriding two methods. Info.plist is set to only allow Portrait, and my view controller implements the following methods:

- (NSUInteger)supportedInterfaceOrientations
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

- (BOOL)shouldAutorotate
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
    return true;
}

我在旋转时看到那些NSLog语句但没有旋转。

I'm seeing those NSLog statements upon rotation but nothing rotates.

如果我使用正确的旋转设置配置Info.plist,我的视图将会旋转,但如果我尝试依赖我的视图控制器则不会。

If I do configure Info.plist with the proper rotation settings, my view will rotate, but not if I try and rely on my view controller.

不确定是否重要,但我正在尝试旋转的视图来自使用自动布局的.xib。

Not sure if it matters, but the view I'm trying to rotate is from a .xib using auto layout.

此外,我的ViewController正在以模态方式呈现并包含在导航控制器中。我试过单独呈现视图控制器,但这不起作用。我也尝试过为UINavigationController添加一个类别它是topViewController的自动旋转方向。

Also, my ViewController is being presented modally and is contained in a navigation controller. I've tried just presenting the view controller by itself and that doesn't work. I've also tried adding a category to UINavigationController to get it's autorotation directions from it's topViewController.

推荐答案

您需要将plist值设置为所有可能的值,然后按照您的看法限制它们fit(在导航控制器和TabBar控制器中。来自UIViewController类描述:

You need to set the plist value to all possible values, then limit them as you see fit (in the Navigation Controllers and TabBar Controllers. From the UIViewController class description:


在iOS 6及更高版本中,您的应用支持接口方向
在应用程序的Info.plist文件中定义。视图控制器可以覆盖
supportedInterfaceOrientations方法来限制
支持的方向列表。通常,系统调用此方法仅
on窗口的根视图控制器或视图控制器
用于填充整个屏幕;子视图控制器使用窗口的
部分提供的f或者他们的父视图
控制器,不再直接参与有关支持
轮换的决定。应用程序的方向
掩码与视图控制器的方向掩码的交集用于确定
视图控制器可以旋转的方向。

In iOS 6 and later, your app supports the interface orientations defined in your app’s Info.plist file. A view controller can override the supportedInterfaceOrientations method to limit the list of supported orientations. Typically, the system calls this method only on the root view controller of the window or a view controller presented to fill the entire screen; child view controllers use the portion of the window provided for them by their parent view controller and no longer participate directly in decisions about what rotations are supported. The intersection of the app’s orientation mask and the view controller’s orientation mask is used to determine which orientations a view controller can be rotated into.

这篇关于在iOS7中处理一个视图控制器的自动旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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