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

  • 相关阅读:
    [转]C++引用
    安装Charles报错
    BigDecimal用法详解
    Map类集合
    Dubbo定义及其作用
    idea常用插件
    GitLab常用命令
    激活idea
    开发微信公众账号报错 返回码详细解释
    微信公众号 iOS UITextFiled 用中文键盘输英文出现空格的解决方法
  • 原文地址:https://www.cnblogs.com/visonhome/p/4253429.html
Copyright © 2011-2022 走看看