QSLBaseNavController.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // QSLBaseNavController.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by mac on 2024/4/10.
  6. //
  7. import UIKit
  8. class QSLBaseNavController: UINavigationController {
  9. override func viewDidLoad() {
  10. super.viewDidLoad()
  11. self.setNavBarAppearence()
  12. self.interactivePopGestureRecognizer?.delegate = self;
  13. }
  14. func setNavBarAppearence() {
  15. // 设置 navbar 背景颜色
  16. self.navigationBar.setBackgroundImage(UIImage.image(color: .white, size: CGSize(width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kNavFrameH)), for: .any, barMetrics: .default)
  17. // 取消 navbar 阴影
  18. self.navigationBar.shadowImage = UIImage()
  19. // 设置文字颜色、大小
  20. var textAttr:[NSAttributedString.Key : Any] = [NSAttributedString.Key : Any]()
  21. textAttr[NSAttributedString.Key.foregroundColor] = UIColor.clear
  22. textAttr[NSAttributedString.Key.font] = UIFont.textM(17)
  23. self.navigationBar.titleTextAttributes = textAttr
  24. if #available(iOS 15.0, *) {
  25. let appearance = UINavigationBarAppearance()
  26. // appearance.backgroundEffect = UIBlurEffect(style: .regular)
  27. appearance.configureWithOpaqueBackground()
  28. appearance.titleTextAttributes = textAttr
  29. appearance.backgroundColor = .white
  30. appearance.shadowColor = .clear
  31. self.navigationBar.standardAppearance = appearance
  32. self.navigationBar.scrollEdgeAppearance = appearance
  33. }
  34. }
  35. }
  36. extension QSLBaseNavController {
  37. /// 设置当跳转到其他页面时隐藏 tabbar
  38. override func pushViewController(_ viewController: UIViewController, animated: Bool) {
  39. if children.count > 0 {
  40. viewController.hidesBottomBarWhenPushed = true
  41. }
  42. super.pushViewController(viewController, animated: animated)
  43. }
  44. }
  45. extension QSLBaseNavController: UIGestureRecognizerDelegate {
  46. /// 跳转到其他页面时开启侧滑
  47. func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
  48. return children.count > 1
  49. }
  50. }