【问题标题】:How to show MPMoviePlayerController in landscape mode如何在横向模式下显示 MPMoviePlayerController
【发布时间】:2014-04-19 15:45:59
【问题描述】:

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

我尝试了一些关于堆栈溢出的事情。在我的情况下没有任何效果。感觉卡在了中间。但我看到一些应用程序支持糟糕的要求。 我必须为 iOS 6、7 实现它

在我的应用中,我使用“XCDYouTubeVideoPlayerViewController”播放视频(播放 youtube 视频)

请帮忙

【问题讨论】:

    标签: ios mpmovieplayercontroller


    【解决方案1】:

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

    首先,您需要通过选中 Target / General / Deployment Info / Deviceorientation 的复选框来启用横向模式,然后您必须在应用中使用的每个 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 的横向,因此在全屏时它可以旋转到横向。

    【讨论】:

    • 好的,我按照你说的试试这个。
    • 感谢您的回复。我刚刚检查过,在少数视图控制器上它可以工作,但在某些视图控制器上却不行。当我到达使用 TabBar 控制器的视图时,代码不起作用并且我的视图能够旋转。请帮忙
    • 我已经发布了一个同样的问题。请看stackoverflow.com/questions/23179515/…
    • 在导航控制器和标签栏控制器的.m文件中也插入上面的代码。
    • @ttdaniI 在 APPDELGATE 类中以编程方式获取它们
    【解决方案2】:

    我有另一个解决方案,它适用于所有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

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      • 1970-01-01
      相关资源
      最近更新 更多