navigationController系统的侧滑pop小记

navigationController系统的侧滑pop小记

系统的侧滑返回一般 我们会做自定义的base nav 做一些全局处理

1
2
3
4
5
6
7
8
9
navigationBar.backIndicatorImage = UIImage(named: "nav_back")
navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "nav_back")
navigationBar.isTranslucent = true
navigationBar.barTintColor = UIColor.white
let attributes = [NSAttributedString.Key.foregroundColor:UIColor.black, NSAttributedString.Key.font:UIFont.systemFont(ofSize: 18)]
navigationBar.titleTextAttributes = attributes
// navigationBar.tintColor = UIColor.white
// navigationBar.setBackgroundImage(UIImage.imageFrom(color: UIColor.white) , for: UIBarMetrics.default)
navigationBar.shadowImage = UIImage()//隐藏线条

重写push

1
2
3
4
5
6
7
if viewControllers.count > 0 {
viewController.hidesBottomBarWhenPushed = true
}
//去掉backBarButtonItem的文字
let item = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
self.topViewController?.navigationItem.backBarButtonItem = item
super.pushViewController(viewController, animated: animated)

然后一般 有些页面我们会重写leftBarButtonItem 会发现 系统自带的侧滑返回失效了
这个时候我们需要做一下处理恢复整个功能
在当前VC 中 (在使用中发现当前vc 销毁后 这个代理会影响原本默认的侧滑,所以放到自定义navVc 中, 去使用了, 且如果不需要侧滑 可以根据最上册的vc 是谁去做特别判断)

1
self.navigationController?.interactivePopGestureRecognizer?.delegate = self

并实现代理

1
2
3
4
5
///UIGestureRecognizerDelegate
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
//当导航控制器的子控制器个数 大于1 手势才有效
return true
}
Author

陈昭

Posted on

2020-04-08

Updated on

2021-12-27

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Kommentare

You forgot to set the shortname for Disqus. Please set it in _config.yml.