iOS 完美解决竖屏项目,个别控制器横屏,反之亦然

引言

一开始试了网上大部分的方法,都没什么用,包括什么强制横屏啥的,特别控制器写了基类的。还要注意在横屏状态下打开APP,看app会不会横屏这样的。

使用

把我下面的方法放在基类控制器,如果导航栏也有基类,也可以一起放进去。
#pragma mark - 默认竖屏 有横屏操作时,presentViewController进入,并实现第二,三个方法。
- (BOOL)shouldAutorotate{//1 允许自动翻转
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{//2 翻转只支持竖屏
    return UIInterfaceOrientationPortrait;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{//3 翻转只支持竖屏
    return UIInterfaceOrientationMaskPortrait;
}

需要横屏的控制器,实现下面的两个方法,注*:需presentViewController进入,如果要导航栏,可以手动添加一个

#pragma mark - 强制横屏
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskLandscapeRight;
}

猜你喜欢

转载自blog.csdn.net/xj_love/article/details/80607184