公司App里面有个需求,即所有界面都是竖屏,且不允许横屏切换,唯独有一个播放视频的界面允许横屏,大家都知道视频播放适配最大的播放屏幕那样是最好的。从网上多方查找资料,查到了这么一篇文章:
Ultimately, this needs to be handled as follows: first, make sure that the app itself should allow the switch to be turned on:
The Uitabbarcontroller in my app is the root view controller, so first create a Uitabbarcontroller subclass and set the Allow to turn screen:
(These are placed in the root view controller, if your app root view is Uinavigationcontroller, just put it in there.)
#pragma mark 转屏方法重写-(UIInterfaceOrientationMask)supportedInterfaceOrientations{ return [self.viewControllers.firstObject supportedInterfaceOrientations];}-(BOOL)shouldAutorotate{ returnself.viewControllers.firstObject.shouldAutorotate;}
- Then, in my Tabbarcontroller, each sub-controller is uinavigationcontroller for the interface push switch, so first create a uinavigationcontroller subclass, and set the Allow to turn the screen:
//self.topViewController是当前导航显示的UIViewController,这样就可以控制每个UIViewController所支持的方向啦!-(BOOL)shouldAutorotate{ return [self.topViewController shouldAutorotate];}- (UIInterfaceOrientationMask)supportedInterfaceOrientations { return [self.topViewController supportedInterfaceOrientations];}
- In the viewcontroller you want to switch the screen can be rewritten as such (allow left and right horizontal screen and vertical screen):
- (BOOL)shouldAutorotate { return NO;}- (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait;}
- To the video playback interface to be set to horizontal screen (my video playback as long as the horizontal screen is good ^_^)
// 是否支持屏幕旋转- (BOOL)shouldAutorotate { returnNO;}- (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape;}-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight;}
Note: Jump to the player to use the modal, with push will error
[Self PRESENTVIEWCONTROLLER:PLAYERVC animated:yes completion:nil];
IOS9 Horizontal Screen Vertical screen setting