How to play landscape video with MPMovieViewController in a portrait-only app

前端 未结 1 1050
野的像风
野的像风 2021-01-02 20:14

My app\'s supported interface orientations are Portrait and Upside down. However, when a video is played, I want it to play full screen landscape. Currently with this code,

相关标签:
1条回答
  • 2021-01-02 20:34

    Here is how I do it:
    In the project file, make sure you are supporting the Landscape Orientations supported interface orientations
    Now in all of your ViewControllers that should still be Portrait Only, add this code

    //ios6
    - (BOOL)shouldAutorotate {
        return NO;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationPortrait;
    }
    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskPortrait;
    }
    
    //ios4 and ios5
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    

    I have put in both the iOS5 and iOS6 calls so that my code will run on both.

    When your MPMoviePlayerController view becomes fullscreen, it will be a new ViewController layered on top of everything else. So, it will be allowed to rotate according to the Supported Interface Orientations of the Project. It will not see where you forced the other ViewControllers into Portrait.

    0 讨论(0)
提交回复
热议问题