MPMoviePlayerViewController不能在横向模式下工作,尤其是View Controller,它在其他View Controller上工作正常

时间:2015-11-02 12:51:08

标签: ios objective-c landscape

我的应用程序包含要以横向模式查看的视频,我应用了以下代码:

- (IBAction)videoAction:(id)sender {

    NSString *path = [[NSBundle mainBundle] pathForResource:@"MTLowRes" ofType:@"mp4"];
    MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
    [self presentModalViewController:moviePlayer animated:NO];
}

AppDelegate.m中管理横向方向的代码如下:

- (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;
        }
    }

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]] ||
        [[self.window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")])
    {
       return UIInterfaceOrientationLandscapeLeft;
    }
    else
    {
        return UIInterfaceOrientationPortrait;
    }
}

此工作正常,但当我选择查看全屏选项时,视频无法全屏旋转。

我尝试在另一个View Controller上应用相同的代码,其中视频在横向全屏模式下工作正常。唯一的问题是使用当前的视图控制器。

0 个答案:

没有答案