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

  • 相关阅读:
    BZOJ1066: [SCOI2007]蜥蜴
    BZOJ1934: [Shoi2007]Vote 善意的投票
    BZOJ2321: [BeiJing2011集训]星器
    BZOJ1076: [SCOI2008]奖励关
    BZOJ1821: [JSOI2010]Group 部落划分 Group
    BZOJ3038: 上帝造题的七分钟2
    NOIP2017滚粗记
    BZOJ1087: [SCOI2005]互不侵犯King
    BZOJ1085: [SCOI2005]骑士精神
    BZOJ1295: [SCOI2009]最长距离
  • 原文地址:https://www.cnblogs.com/cocoajin/p/4828201.html
Copyright © 2011-2022 走看看