iphone - 使用 MPMoviePlayerViewController 时 iPad 旋转错误

标签 iphone objective-c cocoa-touch ipad

问题总结

在使用 MPMoviePlayerViewController 播放视频时更改 iPad 设备或模拟器的方向会导致视频播放器关闭时旋转状态不一致。这是 iPad SDK 3.2 中的一个已知错误,记录在 http://www.openradar.me/8012810

示例项目

我已经使用 Xcode 3.2.2 中基于 View 的应用程序模板准备了一个最小的示例项目,使用以下代码启动播放器

NSURL *movieUrl = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];
[self presentMoviePlayerViewControllerAnimated:player];
[player release];

代码在 GitHub 上可用 http://github.com/adamalex/FullScreenMovie或使用 http://github.com/adamalex/FullScreenMovie/zipball/master 直接下载

重现步骤

  1. 使用以上信息获取项目
  2. 使用 iPad 模拟器或设备启动项目
  3. 点击按钮开始播放视频
  4. 将 iPad 旋转 90 度
  5. 关闭视频
  6. 注意 UIStatusBar 与应用程序 UI 不同步

目标

我已联系 Apple,他们已确认这是一个正在调查中的错误。我想讨论使用公共(public) API 安全提交到 App Store 的临时解决方法。我还将向 Apple 提交一个开发者支持案例,并将报告我自己的进展。

最佳答案

Apple Developer Technical Support 的成功响应!

This is a known bug and a we're received a number of duplicate bug reports and so iOS engineering is aware of the issue and we do have a temporary workaround as suggested by iOS engineering.

You will need to implement this in the view controller which presents the movie player.

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
   [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
   [self performSelector:@selector(fixStatusBar) withObject:nil afterDelay:0];
}

- (void)fixStatusBar {
   [[UIApplication sharedApplication] setStatusBarOrientation:[self interfaceOrientation] animated:NO];
}

While this is somewhat ugly, it should fix the issue for now. It would be recommended to remove this code once the bug is fixed in the system.

这完全解决了我的问题,您可以重新访问 http://github.com/adamalex/FullScreenMovie对于应用了修复程序的代码。

关于iphone - 使用 MPMoviePlayerViewController 时 iPad 旋转错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3089692/

相关文章:

iphone - admob/adsense 如何在 android 应用程序中工作?

iphone - 如何以编程方式从 textview 中关闭键盘

iphone - 当 -adjustsFontSizeToFitWidth 设置为 YES 时,如何计算 UILabel 的字体大小?

iphone - 构建类名形成字符串

iphone - 被触摸的 UIView 的名称

iphone - NSFetchedResultsController 获取请求 - 更新谓词和 UITableView

iphone - Xcode4 导航器中的奇怪符号

iphone - 将字符串与 ABPropertyID 匹配

objective-c - Objective-C 中使用单例保留循环

iphone - 在 iPhone 应用程序中播放连续声音