美文网首页
iOS视频全屏播放下允许横屏

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

作者: 王欣12138 | 来源:发表于2016-06-22 15:54 被阅读670次

```

//.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");

}

```

相关文章

网友评论

      本文标题:iOS视频全屏播放下允许横屏

      本文链接:https://www.haomeiwen.com/subject/skpgdttx.html