使用iOS8旋转YouTube视频

时间:2014-11-18 16:36:44

标签: uiwebview rotation ios8 ios8.1

旋转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上解决这个问题吗?非常感谢你

1 个答案:

答案 0 :(得分:0)

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

在目标设置中,允许应用的横向显示:

enter image description here

在视图控制器中,添加此项以将其限制为纵向:

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}