BaseNavigationController.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // BaseNavigationController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by zhongyuan on 2018/5/9.
  6. // Copyright © 2018年 zhongyuan.All rights reserved.
  7. //
  8. import UIKit
  9. class BaseNavigationController: UINavigationController {
  10. var rightButton: UIButton!
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. // /// 设置返回手势
  14. // setupBackGestureRecognizer()
  15. }
  16. // MARK: - 返回手势相关
  17. func setupBackGestureRecognizer() {
  18. let target = self.interactivePopGestureRecognizer?.delegate
  19. let pan = UIPanGestureRecognizer(target: target, action: Selector(("handleNavigationTransition:")))
  20. pan.delegate = self
  21. self.view.addGestureRecognizer(pan)
  22. self.interactivePopGestureRecognizer?.isEnabled = false
  23. }
  24. override func pushViewController(_ viewController: UIViewController, animated: Bool) {
  25. if self.viewControllers.count >= 1 {
  26. viewController.hidesBottomBarWhenPushed = true
  27. viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "back"), style: .done, target: self, action: #selector(backToParent))
  28. }
  29. super.pushViewController(viewController, animated: animated)
  30. }
  31. @objc func backToParent() {
  32. self.popViewController(animated: true)
  33. }
  34. }
  35. extension BaseNavigationController: UIGestureRecognizerDelegate {
  36. func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
  37. return self.children.count > 1
  38. }
  39. }