appdelega中添加的
@property (nonatomic, assign) BOOL allowRotation;
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.allowRotation) {
return UIInterfaceOrientationMaskPortrait |UIInterfaceOrientationMaskLandscapeLeft |UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait |UIInterfaceOrientationMaskLandscapeLeft |UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
//要旋转的页面添加
1.添加通知
NSNotificationCenter *NSDC = [NSNotificationCenter defaultCenter];
[NSDC addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:_moviePlayer];
[NSDC addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:)
name:MPMoviePlayerWillExitFullscreenNotification
object:_moviePlayer];
2.实现方法
- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification*)notify
{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
delegate.allowRotation = YES;
NSLog(@"moviePlayerWillEnterFullscreenNotification");
}
- (void)moviePlayerWillExitFullscreenNotification:(NSNotification*)notify
{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
delegate.allowRotation = NO;
[self.moviePlayer play];
NSLog(@"moviePlayerWillExitFullscreenNotification");
}