iOS不勾选设置,实现某个界面强制横屏

 1、在不勾选横屏的前提下,实现某一个界面横屏显示,比如播放视频、图表显示等。

2、只能Present跳转,Push会无效。

3、实现代码

     在需要横屏的VC里,添加如下代码     

#pragma mark 强制横屏(针对present方式)
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft);
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}

//必须有
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
}

  

4、最终效果

5、其他补充描述

- 这样设置后,当前页面的坐标原点会变成横屏下的左上角,所以适配规则要按照这个来做。

- 横屏下状态栏是看不到的,这是系统默认实现。

- 这种方式,即使手机本身设置了禁止旋转,也是可以旋转的,所以也是强制旋转。

原文地址:https://www.cnblogs.com/yajunLi/p/6264788.html