【问题标题】:How to play landscape video with MPMovieViewController in a portrait-only app如何在仅纵向应用程序中使用 MPMovieViewController 播放横向视频
【发布时间】:2012-10-22 23:35:42
【问题描述】:

我的应用支持的界面方向是纵向和倒置。但是,当播放视频时,我希望它播放全屏横向。目前使用此代码,即使设备旋转,它也只能播放纵向:

[player.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
player.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self presentMoviePlayerViewControllerAnimated:player];

如何强制它进入横向模式?

【问题讨论】:

标签: ios mpmovieplayercontroller uiinterfaceorientation


【解决方案1】:

我是这样做的:
在项目文件中,确保您支持 Landscape Orientations
现在,在所有仍应为 Portrait Only 的 ViewController 中,添加此代码

//ios6
- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

//ios4 and ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

我已经同时调用了 iOS5 和 iOS6,以便我的代码可以在两者上运行。

当您的 MPMoviePlayerController 视图变为全屏时,它将是一个新的 ViewController,位于其他所有视图之上。因此,将允许根据项目支持的界面方向旋转。它不会看到你在哪里强制其他 ViewControllers 进入 Portrait。

【讨论】:

  • 谢谢,如果必须的话,我会求助于这个,但我希望有一种方法可以做到这一点,而不必将方向代码放在每个视图控制器中(有很多)。
  • 我要做的是创建一个 UIViewController,其中只有这些方法。然后我让我所有需要肖像的 UIViewController 都继承自此,而不是继承自 UIViewController。在 .h 文件的 @interface 行中,我将 MyPortraitViewController 的名称放在 UIViewController 的位置。
  • @soleil,据我了解,这是唯一的方法,不幸的是......原因在 Apple 文档中 UIViewControllersupportedInterfaceOrientations 部分: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.
  • @Walter 的前 3 个方法包含在所有控制器 (iOS6) 的超类中,它仍然在模拟器中自动旋转。我错过了什么吗?
  • 如果你只支持 iOS 7,shouldAutorotate 应该可以完成这项工作
猜你喜欢
  • 1970-01-01
  • 2013-03-27
  • 1970-01-01
  • 2013-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-23
  • 1970-01-01
相关资源
最近更新 更多