且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS 6中的自动旋转具有奇怪的行为

更新时间:2023-11-21 11:39:34

来自Apple的iOS 6 SDK发行说明:

From Apple's iOS 6 SDK Release Notes:


iOS 6中的自动旋转正在发生变化。在iOS 6中,不推荐使用UIViewController的shouldAutorotateToInterfaceOrientation:方法。取而代之的是,您应该使用supportedInterfaceOrientationsForWindow:和shouldAutorotate方法。

Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientationsForWindow: and shouldAutorotate methods.

更多责任转移到应用程序和应用程序委托。现在,iOS容器(例如UINavigationController)不会咨询他们的孩子以确定他们是否应该自动旋转。 默认情况下,应用程序和视图控制器支持的界面方向设置为iPad惯用语的UIInterfaceOrientationMaskAll和iPhone惯用语的UIInterfaceOrientationMaskAllButUpsideDown。

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. By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.

A视图控制器支持的界面方向可以随时间变化 - 即使应用程序支持的界面方向也可能随时间而变化。 每当设备旋转或视图控制器呈现全屏模式演示样式时,系统会询问最顶层的全屏视图控制器(通常是根视图控制器)的支持接口方向。此外,仅当此视图控制器从其shouldAutorotate方法返回YES时,才会检索支持的方向。 系统将视图控制器支持的方向与应用程序支持的方向(由Info.plist文件或应用程序委托的应用程序:supportedInterfaceOrientationsForWindow:方法确定)相交,以确定是否旋转。

A view controller’s supported interface orientations can change over time—even an app’s supported interface orientations can change over time. The system asks the top-most full-screen view controller (typically the root view controller) for its supported interface orientations whenever the device rotates or whenever a view controller is presented with the full-screen modal presentation style. Moreover, the supported orientations are retrieved only if this view controller returns YES from its shouldAutorotate method. The system intersects the view controller’s supported orientations with the app’s supported orientations (as determined by the Info.plist file or the app delegate’s application:supportedInterfaceOrientationsForWindow: method) to determine whether to rotate.

系统通过将应用程序的supportedInterfaceOrientationsForWindow:方法返回的值与最顶层全屏控制器的supportedInterfaceOrientations方法返回的值相交来确定是否支持方向。
setStatusBarOrientation:animated:方法不是直接弃用的。它现在只有在最顶层的全屏视图控制器的supportedInterfaceOrientations方法返回0时才有效。这使调用者负责确保状态栏方向一致。

The system determines whether an orientation is supported by intersecting the value returned by the app’s supportedInterfaceOrientationsForWindow: method with the value returned by the supportedInterfaceOrientations method of the top-most full-screen controller. The setStatusBarOrientation:animated: method is not deprecated outright. It now works only if the supportedInterfaceOrientations method of the top-most full-screen view controller returns 0. This makes the caller responsible for ensuring that the status bar orientation is consistent.

为了兼容性,仍然实现shouldAutorotateToInterfaceOrientation:方法的视图控制器不会获得新的自动旋转行为。 (换句话说,它们不会回退到使用app,app delegate或Info.plist文件来确定支持的方向。)而是使用shouldAutorotateToInterfaceOrientation:方法来合成将由supportedInterfaceOrientations方法返回的信息。 。

For compatibility, view controllers that still implement the shouldAutorotateToInterfaceOrientation: method do not get the new autorotation behaviors. (In other words, they do not fall back to using the app, app delegate, or Info.plist file to determine the supported orientations.) Instead, the shouldAutorotateToInterfaceOrientation: method is used to synthesize the information that would be returned by the supportedInterfaceOrientations method.

如果您希望整个应用程序旋转,那么您应该设置Info.plist以支持所有方向。现在,如果您希望特定视图仅为纵向,则必须执行某种子类并覆盖自动旋转方法以仅返回纵向。我在这里有一个例子:

If you want your whole app to rotate then you should set your Info.plist to support all orientations. Now if you want a specific view to be portrait only you will have to do some sort of subclass and override the autorotation methods to return portrait only. I have an example here:

https://***.com/a / 12522119/1575017