Latest 1.1.0
Homepage https://github.com/spirit-jsb/JSRootNavigationController
License MIT
Platforms ios 9.0, requires ARC
Frameworks UIKit, Foundation
Authors

JSRootNavigationController
JSRootNavigationController
JSRootNavigationController
JSRootNavigationController
JSRootNavigationController

示例代码

如需要运行示例项目,请 clone 当前 repo 到本地,并且从根目录下执行 JSRootNavigationController.xcworkspace,打开项目后切换 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)

tabBarController.viewControllers = [example1Navigation, example2Navigation,example3Navigation, example4Navigation]

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

通过上述方法设置的 UITabBarController 的视图结构如下图:

UITabBarControllerMethod1视图结构

Swift 版本依赖

Swift JSRootNavigationController
4.0 1.0.0~1.0.3
4.2 >= 1.1.0

限制条件

  • iOS 9.0 and Up
  • Xcode 10.0 and Up
  • Swift Version = 4.2

安装

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

pod 'JSRootNavigationController', '~> 1.1.0'

作者

spirit-jsb, [email protected]

许可文件

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

Latest podspec

{
    "name": "JSRootNavigationController",
    "version": "1.1.0",
    "summary": "u4e00u4e2au7b80u4fbfu6613u7528u7684u81eau5b9au4e49 NavigationController u6846u67b6u3002",
    "description": "u4e00u4e2au7b80u4fbfu6613u7528u7684u81eau5b9au4e49 NavigationController u6846u67b6uff0cu4f7fu6bcfu4e2a ViewController u72ecu7acbu7684u7ef4u62a4u5404u81eau7684 NavigationBaru3002",
    "homepage": "https://github.com/spirit-jsb/JSRootNavigationController",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "spirit-jsb": "[email protected]"
    },
    "swift_version": "4.2",
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/spirit-jsb/JSRootNavigationController.git",
        "tag": "1.1.0"
    },
    "source_files": "Sources/**/*.swift",
    "requires_arc": true,
    "frameworks": [
        "UIKit",
        "Foundation"
    ]
}

Pin It on Pinterest

Share This