JSRootNavigationController 2.0.0

JSRootNavigationController 2.0.0

未申报 维护。



  • spirit-jsb

JSRootNavigationController

示例代码

如需运行示例项目,请将当前的 repo clone 到本地,从根目录下执行 JSRootNavigationController.xcodeproj。打开项目后,切换 SchemeJSRootNavigationController-Demo 即可。

JSRootNavigationController 视图结构

JSRootNavigationController 的视图结构如下所示:

JSRootNavigationController视图结构

从上图可以看出,通过 self.navigationController 访问得到的是一个容器导航控制器,即 JSContainerNavigationController。其 viewControllers 的数量始终为 1。因此,若想得到正确的 viewControllers 的数量,应使用以下方法:

let viewControllers = self.js.navigationController.js.viewControllers

关于设置 UITabBarController

由于 JSRootNavigationController 特殊的视图结构,因此有两种设置 UITabBarController 的方法:

方法一

let tabBarController = UITabBarController()
        
let example1 = Example1ViewController()
let example2 = Example2ViewController()
let example3 = Example3ViewController()
let example4 = Example4ViewController()
        
let example1Navigation = JSRootNavigationController(rootViewController: example1)
let example2Navigation = JSRootNavigationController(rootViewController: example2)
let example3Navigation = JSRootNavigationController(rootViewController: example3)
let example4Navigation = JSRootNavigationController(rootViewController: example4)
        
example1Navigation.tabBarItem = UITabBarItem(title: "Example1", image: nil, tag: 0)
example2Navigation.tabBarItem = UITabBarItem(title: "Example2", image: nil, tag: 1)
example3Navigation.tabBarItem = UITabBarItem(title: "Example3", image: nil, tag: 2)
example4Navigation.tabBarItem = UITabBarItem(title: "Example4", image: nil, tag: 3)
        
tabBarController.viewControllers = [example1Navigation, example2Navigation,example3Navigation, example4Navigation]

(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = tabBarController

上述方法设置的 UITabBarController 的视图结构如下所示:

UITabBarControllerMethod1视图结构

方法二

let tabBarController = UITabBarController()
        
let example1 = Example1ViewController()
let example2 = Example2ViewController()
let example3 = Example3ViewController()
let example4 = Example4ViewController()
        
let example1Navigation = JSContainerNavigationController(rootViewController: example1)
let example2Navigation = JSContainerNavigationController(rootViewController: example2)
let example3Navigation = JSContainerNavigationController(rootViewController: example3)
let example4Navigation = JSContainerNavigationController(rootViewController: example4)

example1Navigation.tabBarItem = UITabBarItem(title: "Example1", image: nil, tag: 0)
example2Navigation.tabBarItem = UITabBarItem(title: "Example2", image: nil, tag: 1)
example3Navigation.tabBarItem = UITabBarItem(title: "Example3", image: nil, tag: 2)
example4Navigation.tabBarItem = UITabBarItem(title: "Example4", image: nil, tag: 3)

tabBarController.viewControllers = [example1Navigation, example2Navigation,example3Navigation, example4Navigation]
        
(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = JSRootNavigationController(withNoWrapping: tabBarController)

上述方法设置的 UITabBarController 的视图结构如下所示:

UITabBarControllerMethod1视图结构

Swift 版本依赖

Swift JSRootNavigationController
5.0 >= 2.0.0

限制条件

  • iOS 9.0 及以上版本
  • Xcode 10.0 及以上版本
  • Swift 版本 = 5.0

安装

可以通过 CocoaPods 获得安装 JSRootNavigationController。在项目的 Podfile 中添加如下字段即可:

pod 'JSRootNavigationController', '~> 2.0.0'

作者

spirit-jsb, [email protected]

许可文件

MIT 许可下可以使用 JSRootNavigationController,更多详情请参阅许可文件。