0

我在旋转 youtube 视频时遇到问题。我将以下代码添加到我的应用程序中。它适用于 iOS 7。但是,它不适用于 iOS8。

在我的视图控制器中,我使用了以下代码:

     if(IS_OS_6_OR_LATER){ 
        // I use the following notification for iOS 7
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) latername:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];//Notification

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];//Notification
                }    



if (IS_OS_8_OR_LATER) { 
// I use the following notification for iOS 8
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:UIWindowDidBecomeVisibleNotification object:self.view.window];
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:UIWindowDidBecomeHiddenNotification object:self.view.window];
        }



 -(void) youTubeStarted:(NSNotification*) notif {
    //Handle event 
            AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
            appDelegate.fullScreenVideoIsPlaying = YES;
            NSLog(@"start fullscreen");
        }
        -(void) youTubeFinished:(NSNotification*) notif {
            AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];//Notification
            appDelegate.fullScreenVideoIsPlaying = NO;//Notification
            NSLog(@"exit fullscreen");//Notification
        }



 -(BOOL) shouldAutorotate {
    //Handle rotate
            NSLog(@"AutoState");
            return NO;
        }
        -(NSUInteger)supportedInterfaceOrientations{
    //Handle rotate
            NSLog(@"AutoState 1");
            return UIInterfaceOrientationMaskPortrait;//Notification
        }
        - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    //Handle rotate
            NSLog(@"AutoState 2");
            return UIInterfaceOrientationPortrait;//Notification
        }

在 iOS 7 中,当视频在横向模式下播放时,我按下完成按钮,我看到显示日志“AutoState 1”,但是在使用 iOS 8 运行时我没有看到此日志。你能帮我在 iOS 8 上解决这个问题吗?非常感谢

4

1 回答 1

0

与其将整个应用程序限制为纵向,然后尝试使视频播放器允许横向,您应该在整个应用程序中允许横向,然后将您的个人视图控制器(或根视图控制器)限制为仅允许纵向模式,就像这样:

在目标设置中,允许您的应用使用横向:

在此处输入图像描述

在您的视图控制器中,添加它以将其限制为纵向:

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
于 2015-08-24T10:33:32.453 回答