ios - 在 iOS 6 中,UIViewController 能否支持比其父级更多的界面方向?

标签 ios rotation orientation ios6

iOS 6 中对自动旋转的更改似乎使这变得异常困难,或者说不可能。他们似乎在插入这样一种理念,即 subview Controller 不应该覆盖其父 View Controller 的自动旋转行为。这使得我很难完成我想做的事情:

  • 我有一个必须纵向显示的 View Controller 。
  • 它以模态方式推送另一个 View Controller ,它是一个简单的图像查看器,但我希望这个 View Controller 能够旋转到任何纵向或横向方向(出于显而易见的原因)
  • 当 subview Controller 被关闭时(无论其当前方向如何),父 View Controller 应保持纵向

Relevant Apple Documentation from UIViewController class reference

In iOS 6, 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. Generally, 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 in 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.

我考虑过使用变换来模拟 subview Controller 中的旋转,但老实说,我觉得应该有更好的方法,并且希望尽可能避免这种情况。完全

似乎任何为了让任何 subview Controller 支持界面方向,其父 View Controller (以模态或其他方式呈现)现在也必须支持该界面方向。

我是不是漏掉了一些简单的东西?这是否像看起来那样荒谬?

最佳答案

您可以子类化 Navigation Controller 并覆盖 (NSUInteger)supportedInterfaceOrientations 方法。因此,导航 Controller 将始终返回当前显示的 View Controller 支持的任何内容。

类似下面的内容(代码和想法未经测试):

- (NSUInteger)supportedInterfaceOrientations {
    return [self.presentedViewController supportedInterfaceOrientations];
}

关于ios - 在 iOS 6 中,UIViewController 能否支持比其父级更多的界面方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12755727/

相关文章:

ios - 如何在 Swift 中更改 UIWebView 中文本的行距

ios - 协议(protocol)可选方法在未实现时会崩溃

javascript - 我想制作一个点击后自动旋转的按钮

android - 如何处理在 VirtualBox 上的 android-x86 中强制屏幕方向的应用程序?

ios - 使 Pod 仅可用于测试,不可用于源

ios - UIPageviewController 使用 Storyboard 崩溃

Swift SpriteKit 在 x 轴旋转节点

java - 如何将android开关小部件旋转90°

android - 如何获得相对于设备主体的 Activity 的真实旋转

android - 保存数据和改变方向