// // BaseNavigationController.swift // MTP2_iOS // // Created by Muchinfo on 2020/12/28. // Copyright © 2020 Muchinfo. All rights reserved. // import UIKit /// 导航栏视图容器控制类基类 class BaseNavigationController: UINavigationController, UINavigationControllerDelegate { // MARK: - 生命周期 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. if #available(iOS 13.0, *) { let appearance = UINavigationBarAppearance() appearance.configureWithOpaqueBackground() appearance.backgroundColor = .fromHex(rgbValue: 0x2481DD) appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont.font_18] navigationBar.standardAppearance = appearance navigationBar.scrollEdgeAppearance = navigationBar.standardAppearance } else { // Fallback on earlier versions UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont.font_18] UINavigationBar.appearance().barTintColor = .fromHex(rgbValue: 0x2481DD) } UIBarButtonItem.appearance().tintColor = .white /// 侧边栏滑动手势 self.interactivePopGestureRecognizer?.delegate = self self.delegate = self } // MARK: - 返回手势相关 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 } }