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

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

 

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、最终效果

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

 

5、其他补充描述

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

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

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

 

相关文章:

  • 2022-12-23
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2021-11-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案