iOS8中视频进入时的旋转

4

我在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 8.0.2上完美运行。

请告诉我如果你找到了这个问题的答案/解决方案。我也遇到了完全相同的问题。 - valbu17
@NorthBlast,你找到解决方案了吗?还是遇到同样的问题? - ElioMB
是的,我做了,但不是为了WillExit.. 我有一个可以用作DidExit的.. 我会发布它.. - valbu17
1
UIMoviePlayerControllerDidEnterFullscreenNotification 在 iOS8 中无法工作的问题。 - msk
我认为你现在遇到的问题是布局问题,而不是通知问题,但我今晚会检查一下。 - valbu17
@NorthBlast 这个解决方案让它再次正常工作了 https://dev59.com/g4Pba4cB1Zd3GeqPupoE - ElioMB
1个回答

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

}

希望这能有所帮助!


我遇到了和 @ElioMB 一样的错误,我们能在这里做些什么? - atrik
我试过了,它可以工作!但是如何锁定其他视图控制器的方向? - Boyi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接