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

  • 相关阅读:
    topcoder srm 495 div1
    topcoder srm 500 div1
    topcoder srm 485 div1
    topcoder srm 490 div1
    IDEWorkspaceChecks.plist文件是干什么用的?
    博客推荐
    如何使用U盘安装macOS high Sierra?
    小程序--模板消息调研
    小程序--剖析小程序上传文件
    小程序--小程序开发过程中遇到的问题以及解决方案
  • 原文地址:https://www.cnblogs.com/cocoajin/p/4828201.html
Copyright © 2011-2022 走看看