系统MPMoviePlayerController点击全屏按钮横屏显示方法


系统播放器有自带的监听
//将要进入全屏的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreenScreen:) name: MPMoviePlayerWillEnterFullscreenNotification object:nil];
    //将要推出全屏的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullscreenScreen:) name: MPMoviePlayerWillExitFullscreenNotification object:nil];

添加监听完成之后实现监听方法
//将要进入全屏
-(void)willEnterFullscreenScreen:(NSNotification *)notification{
    
    NSLog(@"将要进入全屏状态");
    if (self.view.bounds.size.width < self.view.bounds.size.height) {
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
    } else {
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
    }
}
//将要推出全屏
-(void)willExitFullscreenScreen:(NSNotification *)notification{
    
    if (self.view.bounds.size.width < self.view.bounds.size.height) {
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
    } else {
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
    }

猜你喜欢

转载自blog.csdn.net/liuya000/article/details/50900121
今日推荐