let pageTabBarController = AppPageTabBarController(viewControllers: [redViewController, greenViewController, blueViewController], selectedIndex: 0)
let toolbarController = AppToolbarController(rootViewController: pageTabBarController)
let menuController = AppMenuController(rootViewController: toolbarController)
window = UIWindow(frame: Device.bounds)
window!.rootViewController = menuController
window!.makeKeyAndVisible()
问问题
274 次
2 回答
0
在这个stackoverflow 问题中,我添加了有关导航控件的更多见解。您可能会发现它很有帮助。要直接回答您的问题,您正在寻找如下所示的代码设置:
import UIKit
import Material
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func applicationDidFinishLaunching(_ application: UIApplication) {
let redViewController = RedViewController()
let greenViewController = GreenViewController()
let blueViewController = BlueViewController()
let pageTabBarController = AppPageTabBarController(viewControllers: [redViewController, greenViewController, blueViewController], selectedIndex: 0)
let toolbarController = AppToolbarController(rootViewController: pageTabBarController)
let menuController = AppMenuController(rootViewController: toolbarController)
let leftViewController = LeftViewController()
let rightViewController = RightViewController()
let navigationDrawerController = NavigationDrawerController(rootViewController: menuController,
leftViewController: leftViewController,
rightViewController: rightViewController)
window = UIWindow(frame: Device.bounds)
window!.rootViewController = navigationDrawerController
window!.makeKeyAndVisible()
}
}
基本思想是您将导航控制器(具有特定导航功能的控制器)分层堆叠。您可以轻松地重新排列控制器以创建不同的流程,并且可以轻松地添加更多导航控制器,例如 SnackbarController。
堆叠视图控制器的顺序取决于您希望导航控制器的行为方式。例如,如果你把MenuController
它放在 ToolbarController 中,一旦你转换 ToolbarController 的 rootViewController,它就会转出。通过将它放在外面,您可以转换 ToolbarController 并且 MenuController 保留在视图层次结构中。
需要注意的一条规则是,您应该始终将 NavigationDrawerController 作为最外层的导航控件,因为left
和right
控制器应始终与所有其他控件重叠。
希望有帮助:)
于 2016-11-11T03:43:08.130 回答
-1
let pageTabBarController = AppPageTabBarController(viewControllers: [redViewController, greenViewController, blueViewController], selectedIndex: 0)
let toolbarController = AppToolbarController(rootViewController: pageTabBarController)
let menuController = AppMenuController(rootViewController: toolbarController)
let navigationController = AppNavigationDrawerController(rootViewController: menuController, leftViewController: leftViewController,rightViewController: rightViewController)
window = UIWindow(frame: Device.bounds)
window!.rootViewController = navigationController
window!.makeKeyAndVisible()
于 2016-11-09T08:30:25.500 回答