{"id":19391203,"url":"https://github.com/micyo202/yznavtabbar","last_synced_at":"2025-04-24T00:31:43.844Z","repository":{"id":91464657,"uuid":"107619897","full_name":"micyo202/YZNavTabBar","owner":"micyo202","description":"UINavigationController与UITabBarController整合","archived":false,"fork":false,"pushed_at":"2017-11-02T01:18:21.000Z","size":975,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T22:51:15.585Z","etag":null,"topics":["ios11","navigationbar","tabbaritem","uinavigationcontroller","uitabbarcontroller"],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/micyo202.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-20T02:01:29.000Z","updated_at":"2025-02-08T08:09:09.000Z","dependencies_parsed_at":"2023-07-17T03:00:17.818Z","dependency_job_id":null,"html_url":"https://github.com/micyo202/YZNavTabBar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micyo202%2FYZNavTabBar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micyo202%2FYZNavTabBar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micyo202%2FYZNavTabBar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micyo202%2FYZNavTabBar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micyo202","download_url":"https://codeload.github.com/micyo202/YZNavTabBar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250539459,"owners_count":21447312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios11","navigationbar","tabbaritem","uinavigationcontroller","uitabbarcontroller"],"created_at":"2024-11-10T10:25:30.272Z","updated_at":"2025-04-24T00:31:43.828Z","avatar_url":"https://github.com/micyo202.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UINavigationController与UITabBarController整合Demo（纯代码模式）\n\n## 效果预览GIF\n\u003cimg src=\"https://github.com/micyo202/YZNavTabBar/raw/master/20171020102449.gif\" alt=\"效果预览\" title=\"效果预览\"\u003e\n\n## 介绍\n**UINavigationController**：同级页面之间的跳转，界面典型的特点就是页面上部有一UINavigationBar导航条，导航条可以设置标题、左上角的按钮（一般用于返回），右上角的按钮，也可以自定义这些元素。\u003cbr\u003e\n**UITabBarController**：父子页面之间的嵌套关系，界面典型的特点是耍耍下部有一UITabBar选项组，通过点击Tab，可切换上面的视图的变换。\u003cbr\u003e\nUIViewController、UINavigationController、UITabBarController三者的整合使用，可以开发出大部分的App应用页面框架。\n\n## 思路\n我们需要把 Navigation View 加到 Tab Bar View 的内容上去，Tab Bar View再加到 Window 上去。\u003cbr\u003e\n就是 Window 套 UITabBarController，UITabBarController 套 UINavigationController, UINavigationController 套 UIViewController。\u003cbr\u003e\n但当页面使用 UITabBarController + UINavigationController 的时候，当跳转到详情页面的时候，如果 UITabBar 仍然存在的话就会造成逻辑混乱，用户体验也会下降，因此我们就有一个在详情页将 UITabBar 隐藏的需求，接下来就来介绍这个框架完美的搭建方式\n\n## 步骤\n### 1.打开Xcode创建一个 Single View App 工程，由于我们这里使用纯代码模式，固工程创建好后删除项目中生成的 ViewController.h、ViewController.m、Main.storyboard 这三个文件，并在 info.plist 文件中，将 Main storyboard file base name 对应的值 Main 删掉。\n\n### 2.创建继承 UINavigationController 的类 MainNavigationController，在其对应的.m文件中\n\n重写 pushViewController 方法，为了控制导航栏 push 页面隐藏底部 tabBar\n```C\n#pragma mark - 重写pushViewController:方法\n- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{\n    if(self.viewControllers.count \u003e 0){\n        [viewController setHidesBottomBarWhenPushed:YES];// 隐藏底部tabBar\n    }\n    [super pushViewController:viewController animated:animated];\n}\n```\n\n### 3.创建继承 UITabBarController 的类 MainTabBarController，在其对应的.m文件中\n\n在 viewDidLoad 方法中代码如下：\n```C\nNSArray *items = @[\n                   @{\n                       CLASS_NAME       :   @\"FirstViewController\",\n                       TITLE            :   @\"第一个\",\n                       IMAGE            :   @\"tabbar_news\",\n                       SELECTED_IMAGE   :   @\"tabbar_newsHL\"\n                       },\n                   @{\n                       CLASS_NAME       :   @\"SecondViewController\",\n                       TITLE            :   @\"第二个\",\n                       IMAGE            :   @\"tabbar_app\",\n                       SELECTED_IMAGE   :   @\"tabbar_appHL\"\n                       },\n                   @{\n                       CLASS_NAME       :   @\"ThirdViewController\",\n                       TITLE            :   @\"第三个\",\n                       IMAGE            :   @\"tabbar_msg\",\n                       SELECTED_IMAGE   :   @\"tabbar_msgHL\"\n                       },\n                   @{\n                       CLASS_NAME       :   @\"FourthViewController\",\n                       TITLE            :   @\"第四个\",\n                       IMAGE            :   @\"tabbar_mine\",\n                       SELECTED_IMAGE   :   @\"tabbar_mineHL\"\n                       }\n                   ];\n\nNSMutableArray  *viewControllers = [[NSMutableArray alloc] init];\n// 使用block方法遍历集合\n[items enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {\n\n    UIViewController *viewController = [[NSClassFromString(obj[CLASS_NAME]) alloc] init];// 根据类名称动态创建类\n    viewController.title = obj[TITLE];\n    viewController.tabBarItem.image = [UIImage imageNamed:obj[IMAGE]];\n    viewController.tabBarItem.selectedImage = [[UIImage imageNamed:obj[SELECTED_IMAGE]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];\n\n    MainNavigationController *mainNav = [[MainNavigationController alloc] initWithRootViewController:viewController];\n    [viewControllers addObject:mainNav];\n\n}];\n\nself.viewControllers = viewControllers;// 设置tabBar视图集合\n```\n\n### 4.创建显示的子视图：FirstViewContoller、SecondViewController、ThirdViewController、FourthViewController\n\n### 5.在 AppDelegate.m 文件中的 didFinishLaunchingWithOptions 方法中添加如下代码：\n```C\n// 隐藏顶部状态栏设为NO\n[UIApplication sharedApplication].statusBarHidden = NO;\n// 设置顶部状态栏字体为白色\n[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;\n\n// 设置主window视图\n_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];\n_window.backgroundColor = [UIColor clearColor];\n\n_mainTabBarController = [[MainTabBarController alloc] init];\n//_mainTabBarController.view.userInteractionEnabled = NO;// 欢迎动画加载期间不允许永不与视图交互，加载完毕后设置为YES即可\n\n// 设置root视图控制器\n_window.rootViewController = _mainTabBarController;\n[_window makeKeyAndVisible];\n```\n好了到这里最基本的整合过程就完成了，可下载本demo进行查看详细代码及运行效果，希望本文章对你有帮助！\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicyo202%2Fyznavtabbar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicyo202%2Fyznavtabbar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicyo202%2Fyznavtabbar/lists"}