zoukankan      html  css  js  c++  java
  • ios 手动控制开启、禁止屏幕旋转

        最近在公司做iPad开发,跟大多数的iPhone应用不一样,iPad程序要求支持横竖屏,但有时候有的页面不需要屏幕旋转,上网搜了很多资料发现都是不可行或者不符合需求的。首先,直接在UIViewController重写父类以下几个方法,发现是不执行的。

    - (BOOL)shouldAutorotate;
    - (NSUInteger)supportedInterfaceOrientations;
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;

     最好,找到了解决,首先新建一个UINavigatetion的分类,然后重写里面的方法

    -(BOOL)shouldAutorotate {//是否支持自动旋转
        return [[self.viewControllers lastObject] shouldAutorotate];
    }
    -(NSUInteger)supportedInterfaceOrientations {//设备支持的方向
        return [[self.viewControllers lastObject] supportedInterfaceOrientations];
    }
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {//方向标识
        return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
    }

      然后,在你的UIViewController里面实现上面几个方法,就可以随心所以控制屏幕的方向问题啦。

  • 相关阅读:
    08.3 属性描述符__get__ __set__ __delete__
    08.2 __getattr__ 和 __getattribute__
    08.1 property 装饰器
    appium脚本编写,元素定位,隐式等待
    appium的安装和介绍
    docker镜像构建
    dockerfile的语法和指令
    docker的registry介绍
    docker-compose使用
    docker部署Jenkins
  • 原文地址:https://www.cnblogs.com/visonhome/p/4253429.html
Copyright © 2011-2022 走看看