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

  • 相关阅读:
    ftp上传下载
    阿里云轻量服务器价格及轻量与ECS服务器区别比较
    找工作
    程序员的精力管理
    应届生如何笔试面试
    java重点总结(一)
    真是面试题汇总(二)
    真实笔试题汇总(一)
    真实面试问题汇总(一)
    Java后端面试准备
  • 原文地址:https://www.cnblogs.com/visonhome/p/4253429.html
Copyright © 2011-2022 走看看