ios - 全屏时防止 MPMoviePlayerController 旋转和缩放到纵向

标签 ios ios5 rotation orientation mpmovieplayercontroller

在 iPhone 4/4s 的 iOS5 应用程序中,我有一个 UIViewController,它的 View 中添加了一个 MPMoviePlayerController View :

[self.view insertSubview:self.fullscreenMoviePlayerController.view atIndex:2];

UIViewController 仅支持横向:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation 
{
  // Return YES for supported orientations.
  return  interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
          interfaceOrientation == UIInterfaceOrientationLandscapeRight;

}

这正确地将旋转锁定为仅横向。但是,当我将 MPVideoPlayerController 设置为全屏显示时,它会被忽略并且视频不再局限于横向并旋转到手机所持的任何方向。

如何防止 MPMoviePlayerController 的视频在全屏模式下旋转到纵向?当手机旋转为纵向时,视频不会旋转,这一点至关重要。

我已经尝试子类化 MPVideoPlayerController 并覆盖 shouldAutorotateToInterfaceOrientation: 但这没有效果。

MPMoviePlayerController 只是 View 的一部分,因此绝对不能使用 MPMoviePlayerViewCotroller。

最佳答案

如果您真的想避免使用 MPMoviePlayerViewController,这似乎相当困难。 一种选择,即使您在全屏模式下似乎也能工作,是手动设置 MPMoviePlayerController View 的框架。 (请注意,在其他 iOS 问题中,有时使用背景 View 会产生不同的结果,但值得一试)。

MyMPMoviePlayerController.view.frame = CGRectMake(0, 0, your numbers, here);

但是,Apple 在他们的文档中说 Controller 的框架应该设置为其父 View 的框架。

[MyMPMoviePlayerController.view setFrame: parentView.bounds];

不太优雅的解决方案,但即使那个不可行也可能有效的解决方案是:

监听 UIDeviceOrientationDidChangeNotification 并获取电影播放器​​的 View 。在其上应用变换、边界和中心(或框架等),使其仍然适合横向 View 。每次它试图旋转离开时,基本上都会将其转换回来。 (这一切都假设你真的不能用 shouldAutorotateToInterfaceOrientation: 阻止它旋转)。

这里唯一的问题是它可能会保持电影的纵向但扭曲 View ,这不是预期的结果。

关于ios - 全屏时防止 MPMoviePlayerController 旋转和缩放到纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11230628/

相关文章:

c# - objective-c和C#的3DES加密结果不同

ios - 无法复制 Target->Build Settings 中的搜索路径设置

iphone - 如何在 mysql 中插入 utf-8 mb4 字符(ios5 中的表情符号)?

iphone - 当应用程序崩溃时如何向 Web 服务发送崩溃报告?

iphone - 旋转 UIView iPhone

android - 如何使用 Fresco Image Viewer 库旋转图像?

ios - 指向非常量类型 Tile * 的指针,没有明确的所有权

ios - 创建带有底部栏的侧边栏菜单动画

ios - Stripe iOS SDK - 发送不兼容的 block 指针类型

ios - "Destroying"委托(delegate)后退按钮(或滑动)[UINavigationController]