【问题标题】:iOS 6 MPMoviePlayerViewController and presentMoviePlayerViewControllerAnimated RotationiOS 6 MPMoviePlayerViewController 和 presentMoviePlayerViewControllerAnimated Rotation
【发布时间】:2012-09-26 01:58:35
【问题描述】:

在以前的 iOS 版本中,我们的视频会自动旋转,但在 iOS 6 中,情况不再如此。我知道 presentMoviePlayerViewControllerAnimated 之前就是为此设计的,但我如何才能告诉 MPMoviePlayerViewController 自动旋转?

MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];

【问题讨论】:

标签: ios iphone ios6 iphone-5


【解决方案1】:

在 appdelegate.m 中:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if ([[self.window.subviews.lastObject class].description isEqualToString:@"MPMovieView"]) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

有点破解,但效果很好......

【讨论】:

  • 旁注: 这是针对 iOS 6+ 的。对于 iOS 5 或更低版本,请使用类似于 UIInterfaceOrientationPortrait 的代码
  • 当我开始一部电影时,我会返回一个描述; 'UITransitionView' 为什么会这样?它与我的视图控制器返回的名称相同
【解决方案2】:

我刚刚遇到了同样的问题。 James Chen 的解决方案是正确的,但我最终做了一些更简单但也有效的事情 - 在我的应用程序委托中覆盖 application:supportedInterfaceOrientationsForWindow 并返回 allButUpsideDown 如果我的 rootView 控制器以模态方式呈现 MPMoviePlayerViewController。不可否认,这是一种 hack,可能并不适用于所有情况,但让我不必更改所有视图控制器:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return [rootViewController.modalViewController isKindOfClass:MPMoviePlayerViewController.class ] ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskAllButUpsideDown;
}

【讨论】:

  • 您好 Jon,首先感谢您的回答。你已经解决了我同样的 MPMoviePlayerViewController 旋转问题但是当我关闭电影播放器​​时,我仍然在 rootViewController.modalViewController 中获得 MPMoviePlayerViewController。我试过了:[self dismissModalViewControllerAnimated:YES];和 [movieControllerdismissMoviePlayerViewControllerAnimated];
【解决方案3】:

这不仅限于MPMoviePlayerViewController。从 iOS 6 开始,自动旋转已更改。见Autorotate in iOS 6 has strange behaviour

要使您的应用程序表现得像 iOS 6 之前的版本,您必须使应用程序支持所有方向(在 plist 中编辑 UISupportedInterfaceOrientations),然后对于所有其他不支持旋转的视图控制器,重写此方法以返回否:

- (BOOL)shouldAutorotate {
    return NO;
}

默认情况下MPMoviePlayerViewController 支持所有方向,所以这应该足以让它工作。

【讨论】:

  • 我更改了我的 plist 文件以允许所有方向,但它没有任何影响。无论方向如何,我的应用程序仍保持纵向模式。我通过代码搜索高低,看看是否有东西阻止旋转,但我什么也没看到。任何想法。
  • @JamesChen 就是这样!如此简单,节省了我挖掘的时间!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-10
  • 2012-04-28
  • 2013-03-31
  • 2015-07-11
  • 1970-01-01
相关资源
最近更新 更多