在iOS 8中输入视频时旋转

时间:2014-09-24 22:09:43

标签: ios objective-c ios8 nsnotificationcenter

我在iOS 7中实现了这个代码并且工作得很好,但是在iOS 8中它不起作用

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];

-(void)youTubeStarted{
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    appDelegate.fullScreenVideoIsPlaying = YES;
}

-(void)youTubeFinished{
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    appDelegate.fullScreenVideoIsPlaying = NO;
}

我尝试将UIMoviePlayerControllerDidEnterFullscreenNotification更改为MPMoviePlayerWillEnterFullscreenNotification。没有运气

还有别的办法吗?

编辑

使用NorthBlast的答案,看看我认为在iOS 8.1中会发生什么。它与iOS 8.0和iOS完美配合。 iOS 8.0.2

enter image description here

1 个答案:

答案 0 :(得分:5)

好的,这是一个解决方案,我现在正在使用..我首先检查哪个操作系统正在运行该设备,然后使用适当的NSNotificationCenter:)

#define IS_OS_6_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
#define IS_OS_8_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

if(IS_OS_6_OR_LATER){

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];

}

if (IS_OS_8_OR_LATER) {

    [[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];

}

我希望它有所帮助!