iOS项目中,只有个别控制器允许横屏

2018-08-06  本文已影响7人  oneYing

首先要允许项目支持横竖屏

一般的项目都会用到navigationController与tabBarController,需要在这二者中先做一些设置


1.navigationController中重写下面有一个方法



-(BOOL)shouldAutorotate

{

return YES;

}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations

{

return [self.viewControllers.lastObject supportedInterfaceOrientations];

}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];

}

2.tabBarController中也重写上述三个方法,得实现时有所不同


- (BOOL)shouldAutorotate

{

return [self.selectedViewController shouldAutorotate];

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations

{

return [self.selectedViewController supportedInterfaceOrientations];

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

return [self.selectedViewController preferredInterfaceOrientationForPresentation];

}

3.在只支持竖屏的controller中也要重写上述方法,支持横屏的controller中不做操作


-(UIInterfaceOrientationMask)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskPortrait ;

}

- (BOOL)shouldAutorotate

{

return NO;

}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

return UIInterfaceOrientationPortrait;

}

如果设置了还不成功。那就有可能是 statusbar style 没有设置,要把Requre full screen 勾选上
demo地址 https://github.com/handnaying/-.git

上一篇下一篇

猜你喜欢

热点阅读