How to show MPMoviePlayerController in landscape mode

亡梦爱人 提交于 2020-01-06 09:54:13

问题


i am working on a app where I am required to show "MPMoviePlayerController" in landscape mode and portrait mode. But My whole app is required to support Portrait mode only. That is no landscape mode for any view other than for the "MPMoviePlayerController".

I tried few things given over stack overflow. Nothing worked in my case. Feels Stuck in the middle. But I have seen some of the app supporting suck kind of requirements. I have to implement it for both iOS 6, 7

In my app am using "XCDYouTubeVideoPlayerViewController" for playing videos(playing the youtube videos)

Please Help


回答1:


I had the same issue, and the following solved the problem:

First you need to allow the Landscape mode either, by checking the checkboxes at Target / General / Deployment Info / Device orientation, and then you have to disable Landscape orientation by code at every ViewController you use in your app.

#pragma mark - Set Supported Device Orientation

//For iOS6
- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

//For iOS4 and iOS5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

But don't disable landscape orientation for the XCYoutubeVideoPlayerViewController, so at fullscreen it can rotate to landscape.




回答2:


I have another solution for this, It will work for all MPMoviePlayerController, below is my code

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)windowx
{
    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]] ||
    [[self.window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")])
    {
        if ([self.window.rootViewController presentedViewController].isBeingDismissed)
        {
        return UIInterfaceOrientationMaskPortrait;
        }
        else
        {
            return UIInterfaceOrientationMaskAllButUpsideDown;
        }
    }
    else
    {
        return UIInterfaceOrientationMaskPortrait;
    }
}

What we basically do here is we enable Landscape orientation for all MPMoviePlayerController classes which are actually MPInlineVideoFullscreenViewController when you present it for fullscreen.

Hope this helps



来源:https://stackoverflow.com/questions/23172081/how-to-show-mpmovieplayercontroller-in-landscape-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!