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

  • 相关阅读:
    mac crontab
    mac 修改MAC代码
    python 二叉树计算器
    python 验证码识别
    scp 上传和下载文件
    centos 开机执行的命令
    centos aws 修改使用密码ssh登录
    python nose测试
    C# linq to xml
    Visual Studio 2015+InstallShield 2015
  • 原文地址:https://www.cnblogs.com/cocoajin/p/4828201.html
Copyright © 2011-2022 走看看