1.info.plist中支持横屏+竖屏
2.appdelegate中只支持竖屏
3.window.rootvc如果是导航或Tab控制器,需要正确书写这两个方法
- (BOOL)shouldAutorotate {
//注意不能直接返回NO,一定要判空
if (self.topViewController) {
return self.topViewController.shouldAutorotate;
}
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
//注意不能直接返回UIInterfaceOrientationMaskPortrait(整型打印为2),一定要判空
if (self.topViewController) {
return self.topViewController.supportedInterfaceOrientations;
}else{
return nil;
}
}
注意:一定要判空
不要像mpaas框架中,手机横着打开app后,页面不能竖屏。
上面这段代码有问题,它的逻辑是:
r0 是 topVC , r0有值返回的是topVC的支持方向
r0没值返回的是2(也就是竖屏)
正确的应该是:r0没值返回 nil。