iOS 6 MPMoviePlayerViewController和presentMoviePlayerViewControllerAnimated Rotation

在之前的iOS版本中,我们的video会自动旋转,但是在iOS 6中,这不再是这种情况。 我知道presentMoviePlayerViewControllerAnimated被devise来做到这一点,但我怎么能告诉MPMoviePlayerViewController自动旋转?

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

在appdelegate.m中:

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

有点破解,但效果很好…

我遇到了同样的问题。 詹姆斯·陈的解决scheme是正确的,但我最终做了一些简单的工作 – 重写应用程序:supportedInterfaceOrientationsForWindow在我的应用程序委托,并返回allButUpsideDown,如果我的rootView控制器模态地呈现MPMoviePlayerViewController。 诚然,一个黑客,可能不适合所有情况,但救了我不得不改变我所有的视图控制器:

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

这不限于MPMoviePlayerViewController 。 从iOS 6开始,自动更改。 请参阅iOS 6中的自动旋转有奇怪的行为 。

为了使你的应用程序像iOS 6之前一样运行,你必须让应用程序支持所有的方向(在plist中编辑UISupportedInterfaceOrientations ),然后对于不支持旋转的所有其他视图控制器,重写此方法返回NO:

 - (BOOL)shouldAutorotate { return NO; } 

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

我发现在iOS 6中有很多类似app的应用程序。但是总的来说,这个解决scheme非常简单: https : //stackoverflow.com/a/13279778/691660