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

  • 相关阅读:
    Foj1675数论
    JSTL与EL之间的千丝万缕
    2013多校联合2 I Warm up 2(hdu 4619)
    ios视图切换之push与present混用
    Ruby设计模式透析之 —— 适配器(Adapter)
    晓说智能指针shared_ptr为何可以实现跨模块分配和释放内存
    CSS的力量
    MySQL-select 1;
    MySQL数据库-语言简介
    Eclipse开发工具提交代码
  • 原文地址:https://www.cnblogs.com/cocoajin/p/4828201.html
Copyright © 2011-2022 走看看