前提:app打开了支持横屏,想要某个页面锁定竖屏
1.如果是没有导航栏的页面,需要在viewController实现
// 是否支持自动转屏
- (BOOL)shouldAutorotate {
return NO;
}
// 支持哪些屏幕方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
2.如果页面有导航控制器,需要自定义一个导航控制器
@interface BaseNavController : UINavigationController
在自定义的导航控制器实现
// 是否支持自动转屏
- (BOOL)shouldAutorotate {
return [self.topViewController shouldAutorotate];;
}
// 支持哪些屏幕方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];;
}
3.有tabBarController管理的页面需要在tabBarController里面实现shouldAutorotate和supportedInterfaceOrientations
网友评论