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

标签 iphone objective-c ios mpmovieplayercontroller ios6

我有 UITabBarController 应用程序,它可以播放视频并在其他 UITabBar 选项卡中显示其他信息。在 iOS 6 中,UIView 旋转方法已被弃用,现在我需要使用 shouldAutoRotatesupportedInterfaceOrientations 方法。对于视频播放,我使用 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 。我这里有一个例子:

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

关于iphone - iOS 6 中的自动旋转有奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12526054/

相关文章:

ios - NSMutableArray有6个(某些示例)项。 3个ID和3个数组(有关这3个ID的信息)。如何删除这些数字(ID)

iphone - 如何让 Uilabel 在 iPhone 中闪烁

ios - 致命异常 NSRangeException -[__NSCFString replaceOccurrencesOfString :withString:options:range:]: Range {N, N} 越界;字符串长度 N

objective-c - KVC——关于数据类型

ios - Objective-C - 离开 ViewController 时 CBCentralManager NSInternalInconsistencyException

ios - 如何使用 Swift 类在数组中添加信息

ios - 有没有办法让 CoreData 与服务器 API 保持同步,即使应用程序处于后台/暂停/终止状态?

iphone - 尝试编辑单元格时 UITableView 崩溃

ios - CMSampleBuffer 到 Swift 中的字节数组

iphone - 从类中调用 View