zoukankan      html  css  js  c++  java
  • 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、其他补充描述

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

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

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

  • 相关阅读:
    tomcat监控与优化
    rpm打包
    Rewrite和location 区别
    LNMP服务
    yum仓库脚本
    用户管理的脚本2
    pxe装机脚本
    用户管理的脚本1
    磁盘管理综合测试题
    MySQL 增量备份介绍及案例演示
  • 原文地址:https://www.cnblogs.com/yajunLi/p/6264788.html
Copyright © 2011-2022 走看看