swift - 统一导航栏"返回"键,并当push隐藏控制器底部tabbar

1、设置自定义返回按钮

var backBtn:UIButton= {

        //设置返回按钮属性

        letbackBtn =UIButton(type:UIButtonType.Custom)

        backBtn.setImage(UIImage(named:"v2_goback"), forState: .Normal)

        backBtn.titleLabel?.hidden=true

        backBtn.addTarget(self, action:"goBack", forControlEvents: .TouchUpInside)

        backBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignment.Left

        backBtn.contentEdgeInsets=UIEdgeInsetsMake(0, -10,0,0)

        letbtnW:CGFloat=ScreenWidth>375.0?50:44

        backBtn.frame=CGRectMake(0,0, btnW,40)

        returnbackBtn

}()

2、重写导航控制器的PUSH方法

override func pushViewController(viewController:UIViewController, animated:Bool) {

        viewController.navigationItem.hidesBackButton=true

        ifchildViewControllers.count>0{

                UINavigationBar.appearance().backItem?.hidesBackButton=false

                viewController.navigationItem.leftBarButtonItem=UIBarButtonItem(customView:backBtn)

               viewController.hidesBottomBarWhenPushed=true

        }

        super.pushViewController(viewController, animated: animated)

}

3、添加返回方法

func  goBack() {

        popViewControllerAnimated(isAnimation)

}

你可能感兴趣的:(swift - 统一导航栏"返回"键,并当push隐藏控制器底部tabbar)