Youtube视频无法在iOS 8中以横向模式播放

pan*_*kaj 5 youtube iphone video ios ios8

我的应用程序包括在横向和纵向模式下播放视频的功能.视频可以是youtube也一切正常,直到iOS 7但现在youtube视频在iOS 8上无法在横向模式下工作.

我的代码:

- (NSUInteger)application:(UIApplication *)applicationsupportedInterfaceOrientationsForWindow:(UIWindow *)window {


  if ([[window.rootViewController presentedViewController]
     isKindOfClass:[MPMoviePlayerViewController class]] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")])        {

      return UIInterfaceOrientationMaskAllButUpsideDown;
  } else {

      if ([[window.rootViewController presentedViewController]
         isKindOfClass:[UINavigationController class]]) {

          // look for it inside UINavigationController
          UINavigationController *nc = (UINavigationController *)[window.rootViewController presentedViewController];

          // is at the top?
          if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]]) {
            return UIInterfaceOrientationMaskAllButUpsideDown;

            // or it's presented from the top?
          } else if ([[nc.topViewController presentedViewController]
                    isKindOfClass:[MPMoviePlayerViewController class]]) {
              return UIInterfaceOrientationMaskAllButUpsideDown;
          }
      }
  } 

  return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)

一切都工作正常,直到iOS 7,但停止在iOS 8上工作.任何帮助赞赏

pan*_*kaj 14

好吧,它有时候很难回答你自己的问题,但它有助于帮助那些面临同样问题的人.

在iOS 8而不是检查MPInlineVideoFullscreenViewController我们需要检查AVFullScreenViewController.以下是所有iOS版本的完整方法,即iOS 8及更低版本.

 - (NSUInteger)application:(UIApplication *)applicationsupportedInterfaceOrientationsForWindow:(UIWindow *)window {

  if ([[window.rootViewController presentedViewController]
     isKindOfClass:[MPMoviePlayerViewController class]] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {

      return UIInterfaceOrientationMaskAllButUpsideDown;
  }else {

      if ([[window.rootViewController presentedViewController]
         isKindOfClass:[UINavigationController class]]) {

          // look for it inside UINavigationController
          UINavigationController *nc = (UINavigationController *)[window.rootViewController presentedViewController];

          // is at the top?
          if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]]) {
              return UIInterfaceOrientationMaskAllButUpsideDown;

              // or it's presented from the top?
          } else if ([[nc.topViewController presentedViewController]
                    isKindOfClass:[MPMoviePlayerViewController class]]) {
              return UIInterfaceOrientationMaskAllButUpsideDown;
          }
      }
  }

  return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)

更新:也 适用于iOS 9

  • 赞成回答你自己的问题并不是愚蠢的.没有回复的叠贴很傻. (4认同)

ove*_*asy 5

我的应用程序中有类似的代码,这在iOS8中也有所突破.

我只是想发布我的修复版本,以防它帮助任何人.

主要的区别是,我只是检查最顶层的控制器.

我认为这比嵌套条件试图弄清楚什么样的vc呈现另一个vc更有意义.

无论如何,我已经在我的应用代表中得到了这个,并且它在8中工作得很好.

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    id presentedViewController = [self topMostController];

    if ( [self vcIsVideoPlayer:presentedViewController] ) {
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

- (UIViewController*) topMostController {
    UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;

    while (topController.presentedViewController) {
        topController = topController.presentedViewController;
    }

    return topController;
}

- (BOOL) vcIsVideoPlayer:(UIViewController *)vc {
    NSString *className = vc ? NSStringFromClass([vc class]) : nil;
    return (
            [className isEqualToString:@"MPInlineVideoFullscreenViewController"] ||
            [className isEqualToString:@"MPMoviePlayerViewController"] ||
            [className isEqualToString:@"AVFullScreenViewController"]
            );
}
Run Code Online (Sandbox Code Playgroud)