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

  • 相关阅读:
    A. Difference Row
    B. Fixed Points
    命运
    Climbing Worm
    大学感想
    Constructing Roads
    lintcode605- Sequence Reconstruction- medium- airbnb google
    lintcode616- Course Schedule II- medium
    lintcode615- Course Schedule- medium
    lintcode127- Topological Sorting- medium
  • 原文地址:https://www.cnblogs.com/visonhome/p/4253429.html
Copyright © 2020-2023  润新知