我有 UITabBarController
应用程序,它可以播放视频并在其他 UITabBar
选项卡中显示其他信息。在 iOS 6 中,UIView
旋转方法已被弃用,现在我需要使用 shouldAutoRotate
和 supportedInterfaceOrientations
方法。对于视频播放,我使用 MPMoviePlayerViewController
。
如何只旋转这个播放器 View ?我只能旋转整个应用程序,但不想这样做。我展示了 MPMoviePlayerViewController
,但它不像在 iOS 5 和更早版本中那样旋转。
在 plist
设置中,我只设置了 1 个纵向界面方向。如果我设置其他 - 整个应用程序将旋转。
最佳答案
来自 Apple 的 iOS 6 SDK 发行说明:
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.
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 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.
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.
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 设置为支持所有方向。现在,如果您希望特定 View 仅显示纵向 View ,您将不得不进行某种子类化并重写自动旋转方法以仅返回纵向 View 。我这里有一个例子:
关于iphone - iOS 6 中的自动旋转有奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12526054/