| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- //
- // BaseNavigationController.swift
- // MTP2_iOS
- //
- // Created by zhongyuan on 2018/5/9.
- // Copyright © 2018年 zhongyuan.All rights reserved.
- //
- import UIKit
- class BaseNavigationController: UINavigationController {
-
- var rightButton: UIButton!
- override func viewDidLoad() {
- super.viewDidLoad()
- // /// 设置返回手势
- // setupBackGestureRecognizer()
- }
-
- // MARK: - 返回手势相关
- func setupBackGestureRecognizer() {
- let target = self.interactivePopGestureRecognizer?.delegate
- let pan = UIPanGestureRecognizer(target: target, action: Selector(("handleNavigationTransition:")))
- pan.delegate = self
- self.view.addGestureRecognizer(pan)
- self.interactivePopGestureRecognizer?.isEnabled = false
- }
- override func pushViewController(_ viewController: UIViewController, animated: Bool) {
- if self.viewControllers.count >= 1 {
- viewController.hidesBottomBarWhenPushed = true
- viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "back"), style: .done, target: self, action: #selector(backToParent))
- }
- super.pushViewController(viewController, animated: animated)
- }
-
- @objc func backToParent() {
- self.popViewController(animated: true)
- }
- }
- extension BaseNavigationController: UIGestureRecognizerDelegate {
- func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
- return self.children.count > 1
- }
- }
|