1.添加系統(tǒng)通知
//即將進入全屏
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreenScreen:) name: MPMoviePlayerWillEnterFullscreenNotification object:nil];
//即將推出全屏
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullscreenScreen:) name: MPMoviePlayerWillExitFullscreenNotification object:nil];
2.實現(xiàn)方法
//將要進入全屏
-(void)willEnterFullscreenScreen:(NSNotification *)notification{
NSLog(@"將要進入全屏狀態(tài)");
if (self.contentView.bounds.size.width < self.contentView.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.contentView.bounds.size.width < self.contentView.bounds.size.height) {
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
} else {
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
}
}