• 什么时候rootViewController至tabbarController时刻,控制屏幕旋转法


    于ios6后,ios系统改变了屏幕旋转的方法,假设您想将屏幕旋转法,在需求rootvc里面制备,例如

    UIViewController *viewCtrl = [[UIViewController alloc] init];  
    UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:viewCtrl];  
    if ([window respondsToSelector:@selector(setRootViewController:)]) {  
        self.window.rootViewController = navCtrl;  
    } else {  
        [self.window addSubview:navCtrl.view];  
    } 

    当root为nav时,你要建立一个nav的子类,进行改动,假设是vc时,直接能够在vc里进行改动,网上已经有非常多的样例了,但假设是tabbar里面嵌套这非常多nav和vc,nav里又有vc我们要怎么弄呢,以下是我调研的一些方法,就是用几个category对nav和tabbarController进行类别的编写,让他们能够分别相应子视图的旋转方向

    UITabBarController+autoRotate

    @interface UITabBarController (autoRotate)
    
    -(BOOL)shouldAutorotate;
    - (NSUInteger)supportedInterfaceOrientations;
    
    @end
    
    
    #import "UITabBarController+autoRotate.h"
    
    @implementation UITabBarController (autoRotate)
    
    - (BOOL)shouldAutorotate {
        return [self.selectedViewController shouldAutorotate];
    }
    - (NSUInteger)supportedInterfaceOrientations {
        return [self.selectedViewController supportedInterfaceOrientations];
    }
    
    @end

    UINavigationController+autoRotate.h

    @interface UINavigationController (autoRotate)
    
    -(BOOL)shouldAutorotate;
    - (NSUInteger)supportedInterfaceOrientations;
    
    @end
    
    @implementation UINavigationController (autoRotate)
    
    - (BOOL)shouldAutorotate {
        return [self.visibleViewController shouldAutorotate];
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
        return [self.visibleViewController supportedInterfaceOrientations];
    }
    
    @end


    UIViewController1.m
    
    - (BOOL)shouldAutorotate {
        return NO;
    }
    - (NSUInteger)supportedInterfaceOrientations {
       return UIInterfaceOrientationMaskPortrait;;
    }
    UIViewController2.m
    
    - (BOOL)shouldAutorotate {
       return YES;
    }
    - (NSUInteger)supportedInterfaceOrientations {
       return UIInterfaceOrientationMaskAll;
    }


    參考文章:IOS6屏幕旋转具体解释(自己主动旋转、手动旋转、兼容IOS6之前系统) , 在IOS应用中从竖屏模式强制转换为横屏模式 , http://stackoverflow.com/questions/12522903/uitabbarcontroller-rotation-issues-in-ios-6


    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    docker部署mysql
    docker安装nginx
    Linux查看日志-grep
    linux系统常用命令
    python爬虫
    unittest中常用的assert语句
    Linux 监控tcp连接数及状态
    linux top命令查看内存及多核CPU的使用讲述
    jmeter的时间戳函数使用
    influxdb基本SQL操作2
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4887834.html
Copyright © 2020-2023  润新知