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