使用系统的MPMoviePlayerController处理多媒体视频文件的时候,会遇到在进行全屏切换时,进入全屏后播放画面会发现还是竖屏模式,这样的话就完全失去了全屏模式的有优势了,浪费了很多屏幕空间,查阅了一些资料,发现可以通过注册监听通知中心关于MPMoviePlayerController控件的进入全屏(MPMoviePlayerWillEnterFullscreenNotification)和退出全屏(MPMoviePlayerWillExitFullscreenNotification)消息,判断当前应用所处状态,之后根据状态来设置屏幕的方向,从而对屏幕旋转方向进行控制。
#import <MediaPlayer/MediaPlayer.h>
@implementation AppDelegate
{
BOOL _isFullScreen;
}
...
@end
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(willEnterFullScreen:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(willExitFullScreen:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];
- (void)willEnterFullScreen:(NSNotification *)notification
{
_isFullScreen = YES;
}
- (void)willExitFullScreen:(NSNotification *)notification
{
_isFullScreen = NO;
}
application:supportedInterfaceOrientationsForWindow:
方法- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (_isFullScreen) {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
按照顺序完成上面几个步骤就可以实现播放器进出全屏后的屏幕方向旋转了。
-完-