今天研究了下强制设置屏幕旋转,在这记录下
如果app需要有界面旋转屏幕的,那么你的General里的Device Orientation里必须设置相对应的旋转支持
然后加入以下代码,这边我的代码是放在了BaseNavigationController里的
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (self.supportPortraitOnly) {
return UIInterfaceOrientationPortrait == toInterfaceOrientation;
}else {
return [self.topViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
if (self.supportPortraitOnly) {
return UIInterfaceOrientationMaskPortrait;
}else{
return [self.topViewController supportedInterfaceOrientations];
}
}
// New Autorotation support.
- (BOOL)shouldAutorotate {
if (self.supportPortraitOnly) {
return NO;
}else{
return [self.topViewController shouldAutorotate];
}
}
这里面的supportPortraitOnly参数传入你是否只支持竖屏状态
如果你的最低层的控制器只是一个ViewController的话,那么这段代码加在你的BaseViewController里就行了
如果你的最低层的控制器只是一个NavgationController的话,那么这段代码加在你的BaseNavgationController里就行了
如果你的最低层的控制器只是一个TabBarController的话,那么这段代码加在你的BaseTabBarController里就行了