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里面实现上面几个方法,就可以随心所以控制屏幕的方向问题啦。

  • 相关阅读:
    java 死锁
    阿里云 zookeeper
    spring 单元测试
    java hashmap分段锁实现
    java lambda 列表生成列表
    springAOP简介
    spring IOC小知识点
    spring中相互依赖的问题
    linux学习02-虚拟机安装CentOS之后联网
    linux学习01-虚拟机VirtualBox上安装centos7,小白第一步
  • 原文地址:https://www.cnblogs.com/visonhome/p/4253429.html
Copyright © 2011-2022 走看看