UINavigationController详解---含iOS8新的API

8 篇文章 0 订阅
4 篇文章 0 订阅

初始化

    //最常用的初始化方法
    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? {
        
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值