- 简介
- Creating Navigation Controllers
- Accessing Items on the Navigation Stack
- Pushing and Popping Stack Items
- Configuring Navigation Bars
- Configuring Custom Toolbars
- Hiding the Navigation Bar
- Accessing the Delegate
- Action Method for Displaying View Controllers
1 简介
在开发app的过程中任何一个项目都会用到UINavigationController,这是一个很有用的控件,它主要控制界面的跳转和导航。
1.1 导航效果图
1.2 导航控制器的对象管理
1.3 导航控制器内的视图
2 Creating Navigation Controllers
/// 使用自定义的navigationBar和toolbar
///
/// - parameter navigationBarClass : AnyClass
/// - parameter toolbarClass : AnyClass
///
/// - returns: UINavigationController
public init(navigationBarClass: AnyClass?, toolbarClass: AnyClass?)
/// 初始化UINavigationController并指定根VC
///
/// - parameter rootViewController : UIViewController
///
/// - returns: UINavigationController
public init(rootViewController: UIViewController)
3 Accessing Items on the Navigation Stack
/// 顶部UIViewController
public var topViewController: UIViewController? { get } // The top view controller on the stack.
/// 当前UIViewController
public var visibleViewController: UIViewController? { get } // Return modal view controller if it exists. Otherwise the top view controller.
/// 当前UINavigationController管理的UIViewController
public var viewControllers: [UIViewController] // The current view controller stack.
/// 替换堆栈控件的[UIViewController]
///
/// - parameter viewControllers : 要替换的视图
/// - parameter animated : 是否动画替换
///
/// - returns: void
@available(iOS 3.0, *)
public func setViewControllers(viewControllers: [UIViewController], animated: Bool)
4 Pushing and Popping Stack Items
/// push进入下一个VC
///
/// - parameter viewController : UIViewController 目标VC
/// - parameter animated : Bool 是否动画跳转
///
/// - returns: void
public func pushViewController(viewController: UIViewController, animated: Bool)
/// pop回到上一个VC
///
/// - parameter animated : Bool 是否动画跳转
///
/// - returns: 当前UIViewController
public func popViewControllerAnimated(animated: Bool) -> UIViewController?
/// pop回到指定VC
///
/// - parameter viewController : UIViewController 目标VC
/// - parameter animated : Bool 是否动画跳转
///
/// - returns: 弹出的[UIViewController]
public func popToViewController(viewController: UIViewController, animated: Bool) -> [UIViewController]?
/// pop回到第一个VC
///
/// - parameter animated : Bool 是否动画跳转
///
/// - returns: 弹出的[UIViewController]
public func popToRootViewControllerAnimated(animated: Bool) -> [UIViewController]?
/// 手势滑动返回的手势
public var interactivePopGestureRecognizer: UIGestureRecognizer? { get }
5 Configuring Navigation Bars
/// 获取UINavigationBar
public var navigationBar: UINavigationBar { get }
/// 是否隐藏UINavigationBar
public var navigationBarHidden: Bool
/// 是否动画隐藏UINavigationBar
///
/// - parameter hidden : 是否隐藏
/// - parameter animated : 是否动画
///
/// - returns: void
public func setNavigationBarHidden(hidden: Bool, animated: Bool)
6 Configuring Custom Toolbars
/// 获取UIToolbar
@available(iOS 3.0, *)
public var toolbar: UIToolbar! { get }
/// 是否隐藏UIToolbar
@available(iOS 3.0, *)
public var toolbarHidden: Bool // Defaults to YES, i.e. hidden.
/// 是否动画隐藏UIToolbar
///
/// - parameter hidden : 是否隐藏
/// - parameter animated : 是否动画
///
/// - returns: void
@available(iOS 3.0, *)
public func setToolbarHidden(hidden: Bool, animated: Bool)
7 Hiding the Navigation Bar
/// 是否点击屏幕隐藏UINavigationBar
@available(iOS 8.0, *)
public var hidesBarsOnTap: Bool
/// 点击屏幕隐藏UINavigationBar的手势
@available(iOS 8.0, *)
unowned(unsafe) public var barHideOnTapGestureRecognizer: UITapGestureRecognizer { get }
/// 是否点击上下滑动隐藏UINavigationBar
@available(iOS 8.0, *)
public var hidesBarsOnSwipe: Bool
/// 滑动隐藏UINavigationBar的手势
@available(iOS 8.0, *)
public var barHideOnSwipeGestureRecognizer: UIPanGestureRecognizer { get }
/// 是否键盘打开时隐藏UINavigationBar
@available(iOS 8.0, *)
public var hidesBarsWhenKeyboardAppears: Bool
/// 是否横屏隐藏UINavigationBar
@available(iOS 8.0, *)
public var hidesBarsWhenVerticallyCompact: Bool
8 Accessing the Delegate
/// 跳转监听
weak var delegate: UINavigationControllerDelegate?
9 Action Method for Displaying View Controllers
/// 和pushViewController:animated:相同的功能,可携带参数传递
///
/// - parameter vc : UIViewController
/// - parameter sender : 携带参数
///
/// - returns: void
func showViewController(_ vc: UIViewController, sender sender: AnyObject?)
其他
源代码
参考资料
UINavigationController Class Reference
文档修改记录
时间 | 描述 |
---|---|
2016-01-09 | 博文完成 |