zoukankan      html  css  js  c++  java
  • iOS 6.0以上版本的旋屏控制处理

    我们都知道,在iOS 6.0以下,支持旋屏的函数如下:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

    我们只要对不同的interfaceOrientation返回YES或NO即可支持对应的屏幕旋转。在6.0以后,旋转函数改为:

    - (NSUInteger)supportedInterfaceOrientations

    需要自己返回对应的orientations。

    但是在实践中发现,当个controller的supportedInterfaceOrientations根本没有调用。经过查看资料分析,原来在6.0以上,旋屏的控制放在了navgationController,所以我们需要自定义一个navgationController,定义相关的变量来处理是否支持旋转。

    //写子类NavigationController的目的是因为6.0以上,把旋屏的控制放在了UINavigationController

     @interface LRNavigationController : UINavigationController

     //是否支持旋屏幕

    @property(nonatomic,assign)BOOL shouldRotate;

     @end

    实现如下:

    @implementation LRNavigationController

     @synthesize shouldRotate = _shouldRotate;

    #pragma  mark roate method

    - (BOOL)shouldAutorotate

    {

        return_shouldRotate;

    }

     - (NSUInteger)supportedInterfaceOrientations{

        return_shouldRotate ? UIInterfaceOrientationMaskAllButUpsideDown : UIInterfaceOrientationMaskPortrait;

    }

    这样在6.0以上,就可以通过获取navgationController更改_shouldRotate的值,实现旋转的控制。

     

     

  • 相关阅读:
    JavaScript 的历史
    阿里面试题:
    DBA_Oracle基本体系架构(概念)
    java内存管理机制
    HashMap的内部实现机制,Hash是怎样实现的,什么时候ReHash
    HashMap实现原理分析
    堆栈
    数据结构:HDU 2993 MAX Average Problem
    数学(欧拉函数):UVAOJ 11426 GCD
    搜索(DLX):HOJ 1017
  • 原文地址:https://www.cnblogs.com/vicstudio/p/3102621.html
Copyright © 2011-2022 走看看