6

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

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

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

4

1 回答 1

11

我是这样做的:
在项目文件中,确保您支持横向方向 支持的界面方向
现在在所有仍应为纵向的 ViewControllers 中,添加此代码

//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。

于 2012-10-23T00:11:57.943 回答