zoukankan      html  css  js  c++  java
  • iOS 控制单个控制器旋转

    iOS 控制单个控制器旋转

    控制单个ViewController 的旋转

    //不旋转,保持竖屏
    
    //iOS 5
    - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
    }
    //iOS 6
    - (BOOL)shouldAutorotate
    {
        return NO;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationPortrait;
    }
    //始终保持横屏
    
    //iOS 5
    - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return (toInterfaceOrientation == self.preferredInterfaceOrientationForPresentation);
    }
    //iOS 6
    - (BOOL) shouldAutorotate
    {
        return YES;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscapeRight;
    }
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationLandscapeRight;
    }

    然而上面的代码在有 导航条的情况下,并不好用;解决方式,为导航条UINavigationController 创建一个 分类,并使用如下分类的导航条 

    @implementation UINavigationController (Rotation)
     -(BOOL)shouldAutorotate {
             return [[self.viewControllers lastObject] shouldAutorotate];
         }
    
     -(NSUInteger)supportedInterfaceOrientations {
             return [[self.viewControllers lastObject] supportedInterfaceOrientations];
         }
    
     - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
             return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
         }
     @end

    参考 http://blog.csdn.net/wudizhukk/article/details/8674393

  • 相关阅读:
    iOS 调试心得
    一步一步带你安装史上最难安装的 vim 插件
    20 行代码极速为 App 加上聊天功能
    在通知栏上玩游戏,Steve iOS 游戏实现思路
    ThinkPHP 3.2.x 集成极光推送指北
    MkDocs 文档生成逻辑浅析
    极光推送的角标问题
    聊天界面-自适应文字
    Python3.7源码包编译安装
    Navicat远程连接MySQL数据库
  • 原文地址:https://www.cnblogs.com/cocoajin/p/4828201.html
Copyright © 2011-2022 走看看