首页 文章

如何在仅限肖像的应用程序中使用MPMovieViewController播放风景视频

提问于
浏览
6

我的应用程序支持的界面方向是纵向和上下颠倒 . 但是,播放视频时,我希望它能够播放全屏风景 . 目前使用此代码,即使设备旋转,它也只播放肖像:

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

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

1 回答

  • 11

    我是这样做的:
    在项目文件中,确保您支持横向方向
    supported interface orientations

    现在,在所有仍应为Portrait Only的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的位置 .

相关问题