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)
}