JSRootNavigationController
示例代码
如需要运行示例项目,请 clone
当前 repo
到本地,并且从根目录下执行 JSRootNavigationController.xcodeproj
,打开项目后切换 Scheme
至 JSRootNavigationController-Demo
即可。
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
的视图结构如下图:
方法二
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
的视图结构如下图:
Swift 版本依赖
Swift | JSRootNavigationController |
---|---|
5.0 | >= 2.0.0 |
限制条件
- iOS 9.0 and Up
- Xcode 10.0 and Up
- Swift Version = 5.0
安装
JSRootNavigationController
可以通过 CocoaPods 获得。安装只需要在你项目的 Podfile
中添加如下字段:
pod 'JSRootNavigationController', '~> 2.0.0'
作者
spirit-jsb, [email protected]
许可文件
JSRootNavigationController
可在 MIT
许可下使用,更多详情请参阅许可文件。