• iOS正确解决隐藏导航栏后push和pop或dismiss和present闪黑问题


    情景: 一级页面不显示导航栏 ,二级页面显示导航栏.

    方法一 适用于push/pop:

    一级页面中 

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
    
        [self.navigationController setNavigationBarHidden:YES animated:animated];
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];
    
        [self.navigationController setNavigationBarHidden:NO animated:animated];
    }

    方法二(都适用):

     设置self为导航控制器的代理,实现代理方法,在将要显示控制器中设置导航栏隐藏和显示,使用这种方式不仅完美切合滑动返回手势,同时也解决了切换tabBar的时候,导航栏动态隐藏的问题.

    @interface HomePageController () <UINavigationControllerDelegate>
    
    @end
    
    @implementation HomePageController 
    
    #pragma mark - lifeCycle
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        // 设置导航控制器的代理为self
        self.navigationController.delegate = self;
    }
    
    #pragma mark - UINavigationControllerDelegate
    // 将要显示控制器
    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
        // 判断要显示的控制器是否是自己
        BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    
        [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
    }

     写个基类viewcontroller,只要在基类viewcontroller中:

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        [self.navigationController setNavigationBarHidden:self.navigationHidden animated:animated];
    }

    这样你就随心所欲的控制了,只要你想要hidden。给navigationHidden属性赋值yes就好了。

  • 相关阅读:
    javascript与jQuery
    dedecms5.7怎么安装百度编辑器
    Vue.js前端MVVM框架实战篇
    MySQL索引工作原理
    伪静态规则写法RewriteRule-htaccess详细语法使用
    Apache Rewrite 规则详解知识大全
    简单layer 快速上手
    织梦熊掌号主动推送(实时)
    jsonp原生js代码示例
    rgba()和opacity的使用
  • 原文地址:https://www.cnblogs.com/dianming/p/7009435.html
Copyright © 2020-2023  润新知