初始化
//最常用的初始化方法
override init(rootViewController: UIViewController) {
super.init(rootViewController:rootViewController)
}
//自定义NavigationBar或者UIToolBar的时候用这个初始化方法,两个都传nil,则用系统默认的
//展示前必须加入rootviewcontroller
override init(navigationBarClass: AnyClass!, toolbarClass: AnyClass!) {
super.init(navigationBarClass:navigationBarClass,toolbarClass:toolbarClass)
}
获取栈中的Controller
//naviController栈最顶部的controller
self.navigationController?.topViewController
//可见的controller,包括模式跳转出来的controller
self.navigationController?.visibleViewController
//所有的controller
self.navigationController?.viewControllers
//用新的viewControllers替换栈中的viewControllers
self.navigationController?.setViewControllers([], animated: false)
跳转
let viewController = UIViewController() as UIViewController
//压栈
self.navigationController?.pushViewController(viewController, animated: true)
//跳转到上一级
self.navigationController?.popViewControllerAnimated(true)
//跳转到第一个viewcontroller
self.navigationController?.popToRootViewControllerAnimated(true)
//跳转到特定的viewcontroller
self.navigationController?.popToViewController(viewController, animated: true)
NavigationBar(含iOS8新的API)
//只读
self.navigationController?.navigationBar
//设置隐藏navigationbar
self.navigationController?.setNavigationBarHidden(true, animated: true)
//以下为iOS8所有
//当设置为true时,如果有没处理的点击手势就会隐藏和现实navigationBar
self.navigationController?.hidesBarsOnTap = true
//当设置为true时,滑动手势就会隐藏和现实navigationBar(左隐藏右显示)
self.navigationController?.hidesBarsOnTap = true
//当设置为true时,横向方向时隐藏NavigationBar
self.navigationController?.hidesBarsWhenVerticallyCompact = true
//当设置为true时,键盘出现时隐藏NavigationBar
self.navigationController?.hidesBarsWhenKeyboardAppears = true
//获取NavigationBar是否隐藏了
let hiddenOrNot = self.navigationController?.navigationBarHidden
//获取能够隐藏navigationBar的滑动手势
self.navigationController?.barHideOnSwipeGestureRecognizer
//获取能够隐藏navigationBar的点击手势
self.navigationController?.barHideOnTapGestureRecognizer
toolbar
//UIToolBar用来展示一些Action按钮
self.navigationController?.toolbar
self.navigationController?.setToolbarHidden(false, animated: false)
let toolHiddenOrNot = self.navigationController?.toolbarHidden
delegate
//navigation将要显示viewcontroller的view之前
func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
}
//navigation将要显示viewcontroller的view之后
func navigationController(navigationController: UINavigationController, didShowViewController viewController: UIViewController, animated: Bool) {
}
//navigation支持的方向
func navigationControllerSupportedInterfaceOrientations(navigationController: UINavigationController) -> Int {
return 1
}
//presentaion的方向
func navigationControllerPreferredInterfaceOrientationForPresentation(navigationController: UINavigationController) -> UIInterfaceOrientation {
return .Portrait
}
//跳转动画
func navigationController(navigationController: UINavigationController, interactionControllerForAnimationController animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
}
//跳转动画
func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
}