iOS视频全屏播放下允许横屏

2016-06-22  本文已影响670人  王欣12138

```

//.h

@interfaceAppDelegate:UIResponder

@property(strong,nonatomic)UIWindow*window;

@property(nonatomic,assign)BOOLallowRotation;

@end

//.m

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window{

if (self.allowRotation) {

returnUIInterfaceOrientationMaskPortrait |UIInterfaceOrientationMaskLandscapeLeft |UIInterfaceOrientationMaskLandscapeRight;

}returnUIInterfaceOrientationMaskPortrait;

}

- (NSUInteger)supportedInterfaceOrientations {

returnUIInterfaceOrientationMaskPortrait |UIInterfaceOrientationMaskLandscapeLeft |UIInterfaceOrientationMaskLandscapeRight;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

returnUIInterfaceOrientationPortrait;

}

//在MPMovieController所在的类里添加/**

*  添加通知监控媒体播放控制器状态

*/-(void)addNotification{NSNotificationCenter*noti = [NSNotificationCenterdefaultCenter];

[noti addObserver:selfselector:@selector(moviePlayerWillEnterFullscreenNotification:)

name:MPMoviePlayerWillEnterFullscreenNotification object:_moviePlayer];

[noti addObserver:selfselector:@selector(moviePlayerWillExitFullscreenNotification:)            name:MPMoviePlayerWillExitFullscreenNotification object:_moviePlayer];

}

- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification*)notify

{

AppDelegate  *delegate = (AppDelegate *)[[UIApplicationsharedApplication] delegate];

delegate.allowRotation=YES;NSLog(@"moviePlayerWillEnterFullscreenNotification");

}

- (void)moviePlayerWillExitFullscreenNotification:(NSNotification*)notify

{

AppDelegate  *delegate = (AppDelegate *)[[UIApplicationsharedApplication] delegate];

delegate.allowRotation=NO;

[self.moviePlayerplay];NSLog(@"moviePlayerWillExitFullscreenNotification");

}

```

上一篇 下一篇

猜你喜欢

热点阅读