如何在横向模式下显示MPMoviePlayerController

时间:2014-04-19 15:46:00

标签: ios mpmovieplayercontroller

我正在开发一个我需要展示的应用程序" MPMoviePlayerController"在横向模式和纵向模式下。但我的整个应用程序只需要支持纵向模式。对于" MPMoviePlayerController"以外的任何视图,这都不是横向模式。

我在堆栈溢出时尝试了很少的东西。在我的案例中没有任何作用。感觉被困在中间。但我看到一些应用程序支持糟糕的要求。 我必须为iOS 6,7实现它

在我的应用程序中使用" XCDYouTubeVideoPlayerViewController"用于播放视频(播放YouTube视频)

请帮助

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,以下问题解决了这个问题:

首先,您需要通过选中目标/常规/部署信息/设备方向的复选框来允许横向模式,然后您必须在应用中使用的每个ViewController上通过代码禁用横向方向。

#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);
}

但是不要禁用XCYoutubeVideoPlayerViewController的横向方向,因此在全屏时它可以旋转到横向。

答案 1 :(得分:0)

我有另一个解决方案,它适用于所有MPMoviePlayerController,下面是我的代码

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

我们在这里基本上做的是为所有MPMoviePlayerController类启用横向方向,当您将其显示为全屏时,这些类实际为MPInlineVideoFullscreenViewController

希望这有帮助

相关问题