RTRootNavigationController的三个使用上会遇到的bug

一、tabbarcontroller 复杂跳转导致tabbarcontroller切换了子视图但是nav的子视图依然在最上面
官方推荐在UITableBarController中的子视图是Nav导航控制器时,使用
RTRootNavigationController *rootVC = [[RTRootNavigationController alloc] initWithRootViewControllerNoWrapping:tabbar];
tabbar的子视图为RTContainerNavigationController
这样会导致一个问题,就是如果tabbar的一个nav子视图进行push操作时,在这个新push的子视图进行tabbar的子视图切换时,这个被push的子视图还会在上层,仔细看就会发现,在进行push时,下面的tabbar消失了,说明这时候的push并没有push的层次结构

解决办法,全部使用RTRootNavigationController
注意在使用tabbar添加子视图用RTRootNavigationController包装
RTRootNavigationController *nav = [[RTRootNavigationController alloc] initWithRootViewController:childVc];
之后,实际上tabbar添加的nav的取值为
子视图.rt_navigationController,这才是遍历tabbar的viewcontroller中的值,如果取navigationcontroller就是另一层的nav,类型为RTContainerNavigationController,这个不是tabbar中viewcontroller的子视图
二、在使用setviewcontroller进行多重页面跳转,会导致导航栏出现浅白色
这是因为设置导航栏的方法放到了viewdidload中,在使用setviewcontroller重新压栈viewdidload方法将不会被调用,作者根据我提出的问题作出了以下三种解决方案
https://github.com/rickytan/RTRootNavigationController/issues/220

1、墙裂推荐
你的 - setNav 方法放到 - viewWillAppear: 中

  • (void)viewWillAppear:(BOOL)animated
    {
    [super viewWillAppear:animated];
    [self setNav];
    }

2、(不是太好)

  • setViewControllers: 用新实例:
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [self.rt_navigationController setViewControllers:@[[TestViewController new]]];
    });

3、(不推荐)
使用 UIAppearance 来设置全局样式(但是有个问题,就是在setviewcontroller之后就会采用以下的样式,如果有多个页面有不同的导航样式,就不能满足需求了)
这里需要这样设置:
[[UINavigationBar appearance] setShadowImage:[UIImage imageWithColor:[UIColor clearColor]]]; //导航栏分割线
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forBarMetrics:UIBarMetricsDefault]; //导航栏背景图片

三、在实现滚动视图导航栏渐变功能的时候,出现个问题,就是当我程序推到后台,再进入app时,滚动视图会自行下移,个人猜测应该是此时导航栏颜色不是透明的,就导致滚动视图下移
解决办法:强制声明,视图扩展到透明bar区域

self.extendedLayoutIncludesOpaqueBars = YES;

再次感谢rtnav作者的开源!

你可能感兴趣的:(RTRootNavigationController的三个使用上会遇到的bug)