美文网首页
iOS正确解决隐藏导航栏后push和pop或dismiss和pr

iOS正确解决隐藏导航栏后push和pop或dismiss和pr

作者: 码农_会写诗 | 来源:发表于2017-12-28 10:08 被阅读0次

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

    方法一 适用于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 ()

    @end

    @implementation HomePageController

    #pragmamark - lifeCycle

    - (void)viewDidLoad {

        [super viewDidLoad];

        // 设置导航控制器的代理为

    selfself.navigationController.delegate= self;

    }#pragmamark - UINavigationControllerDelegate// 将要显示控制器- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

        // 判断要显示的控制器是否是自己BOOL isShowHomePage = [viewController isKindOfClass:[selfclass]];

        [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];

    }

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

    - (void)viewWillAppear:(BOOL)animated {

        [super viewWillAppear:animated];

        [self.navigationController setNavigationBarHidden:self.navigationHidden animated:animated];

    }

    相关文章

      网友评论

          本文标题:iOS正确解决隐藏导航栏后push和pop或dismiss和pr

          本文链接:https://www.haomeiwen.com/subject/zsntgxtx.html