iOS 导航栏之RTNV解读笔记

表达比较乱,仅作为自己理解顺便记个笔记

//根视图
RTRootNavigationController 
|  在push方法跳转的时候,会拿到即将要跳转的控制器 XViewController  
|  /** 注意 */,以下用X代替 
|  创建RTContainerController 将X当做其子控制器 

RTContainerController
|  RTContainerController containerControllerWithController 会创   建一个当前类,并且将X加入其子控制器
|  之后- (instancetype)initWithNavigationBarClass:(nullable Class)navigationBarClass toolbarClass:(nullable) 会创建containerNavigationController 填充 X 
|  这时候,的层级关系是 RTContainerNavigationController 是X 的导航栏控制器
|  之后 [self addChildViewController:self.containerNavigationController]RTContainerController 添加此导航栏控制器作为其子控制器
| 这样的话,就形成了,当前嵌套的视图层级

RTContainerNavigationController
XViewController

另附 tabbarController,隐藏底部的初始化方法

	self.tabbarVC = [[XXTabViewController alloc]init];
    RTRootNavigationController *tabbarVC = [[RTRootNavigationController alloc]initWithRootViewController:self.tabbarVC];
    
    RTContainerNavigationController *firstContainVC = [[RTContainerNavigationController alloc]initWithRootViewController:[[FViewController alloc]init]];
    firstContainVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"第一页" image:nil tag:0];
    RTContainerNavigationController *secondContainVC = [[RTContainerNavigationController alloc]initWithRootViewController:[[SViewController alloc]init]];
    secondContainVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"第二页" image:nil tag:1];
    
 self.tabbarVC.viewControllers = @[firstContainVC,secondContainVC];
       
 self.window.rootViewController = tabbarVC;
注意,自视图的层级添加在了 RTContainerNavigationController 上,这样的话,整个tabbar的nv就是一个,这样点击tabbar的内部视图的时候,就会以tabbar的根导航push 从而达到隐藏底部的功能
***无需再 [app.tabbarVC.navigationController push...]***

这样的设置对应导航标题的话不可以直接设置self.title
改为 [self.navigationItem setTitle:@"XX"];

或者
 self.tabbarVC = [[XXTabViewController alloc]init];
    
    RTRootNavigationController *tabbarNaviVC = [[RTRootNavigationController alloc]initWithRootViewControllerNoWrapping:self.tabbarVC];
    
    FViewController *f = [[FViewController alloc]init];
    UITabBarItem *f_team = [[UITabBarItem alloc] initWithTitle:@"home" image:[UIImage imageNamed:@"home"] selectedImage:[UIImage imageNamed:@"home_high"]];
    RTRootNavigationController *firstContainVC = [[RTRootNavigationController alloc]initWithRootViewController:f];
    f.tabBarItem = f_team;
    
    SViewController *s = [[SViewController alloc]init];
    UITabBarItem *s_team = [[UITabBarItem alloc] initWithTitle:@"home" image:[UIImage imageNamed:@"home"] selectedImage:[UIImage imageNamed:@"home_high"]];
    s.tabBarItem = s_team;
    RTRootNavigationController *secondContainVC = [[RTRootNavigationController alloc]initWithRootViewController:s];
    
    self.tabbarVC.viewControllers = @[firstContainVC,secondContainVC];
       
    self.window.rootViewController = tabbarNaviVC;

用路由跳转的时候判断
if (self.tabBarController) {
        [self.rt_navigationController pushViewController:XX animated:YES];
    }else{
        AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
        app.tabbarVC.rt_navigationController push...
    }

你可能感兴趣的:(navi,iOS,导航栏)