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

查看:14
本文介绍了在 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 设置为只允许纵向,我的视图控制器实现了以下方法:

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 值设置为所有可能的值,然后根据需要限制它们(在 Navigation Controllers 和 TabBar Controllers 中.来自 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 方法来限制列表支持的方向.通常,系统只调用这个方法在窗口或视图控制器的根视图控制器上呈现以填满整个屏幕;子视图控制器使用他们的父视图为他们提供的窗口部分控制者,不再直接参与关于什么的决定支持旋转.应用程序方向的交集掩码和视图控制器的方向掩码用于确定视图控制器可以旋转到哪些方向.

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天全站免登陆