109 lines
3.5 KiB
Swift
109 lines
3.5 KiB
Swift
//
|
|
// BaseNavigationViewController.swift
|
|
// yinmeng-ios
|
|
//
|
|
// Created by MaiMang on 2024/2/21.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class BaseNavigationViewController: UINavigationController, UIGestureRecognizerDelegate,UINavigationControllerDelegate {
|
|
|
|
|
|
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
|
|
if children.count > 0 {
|
|
viewController.hidesBottomBarWhenPushed = true
|
|
|
|
let mai_image22 = UIImage.init(named: "public_back_white")!
|
|
|
|
let mai_backItem33 = UIBarButtonItem.init(image:mai_image22, style: .plain, target: self, action: #selector(backAction))
|
|
viewController.navigationItem.leftBarButtonItem = mai_backItem33
|
|
}
|
|
super.pushViewController(viewController, animated: animated)
|
|
hideNavigationBarLineImageView(vc: viewController)
|
|
}
|
|
|
|
override var preferredStatusBarStyle: UIStatusBarStyle
|
|
{
|
|
return .lightContent
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
navigationBar.isTranslucent = false
|
|
let mai_font22 = UIFont.systemFont(ofSize: 18, weight: .medium)
|
|
let mai_colorone = UIColor.firstText
|
|
// 去掉导航栏蒙版效果
|
|
let mai_titleTextAttributesmang = [NSAttributedString.Key.font:mai_font22,NSAttributedString.Key.foregroundColor:mai_colorone]
|
|
UINavigationBar.appearance().titleTextAttributes = mai_titleTextAttributesmang
|
|
UINavigationBar.appearance().tintColor = UIColor.red
|
|
UINavigationBar.appearance().backgroundColor = UIColor.viewBackGround
|
|
|
|
UIBarButtonItem.appearance().setTitleTextAttributes(mai_titleTextAttributesmang, for: .normal)
|
|
UIBarButtonItem.appearance().setTitleTextAttributes(mai_titleTextAttributesmang, for: .disabled)
|
|
|
|
|
|
if responds(to: #selector(getter: interactivePopGestureRecognizer)) {
|
|
interactivePopGestureRecognizer?.delegate = self
|
|
}
|
|
|
|
if #available(iOS 13.0, *) {
|
|
let mai_appearance33 = UINavigationBarAppearance()
|
|
mai_appearance33.configureWithOpaqueBackground()
|
|
mai_appearance33.backgroundColor = UIColor.viewBackGround
|
|
mai_appearance33.titleTextAttributes = mai_titleTextAttributesmang
|
|
navigationBar.standardAppearance = mai_appearance33
|
|
navigationBar.tintColor = UIColor.red
|
|
UINavigationBar.appearance().scrollEdgeAppearance = navigationBar.standardAppearance
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
|
|
if children.count <= 1 {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
|
|
if self != navigationController {
|
|
return
|
|
}
|
|
if navigationController.viewControllers.first == viewController {
|
|
navigationController.interactivePopGestureRecognizer?.isEnabled = false
|
|
} else {
|
|
navigationController.interactivePopGestureRecognizer?.isEnabled = true
|
|
}
|
|
}
|
|
|
|
@objc func backAction() -> Void {
|
|
_ = popViewController(animated: true)
|
|
}
|
|
|
|
func hideNavigationBarLineImageView(vc:UIViewController) -> Void {
|
|
let mai_LineImagemangView = findNavigationBarLineImageView(view: vc.navigationController?.navigationBar)
|
|
mai_LineImagemangView?.isHidden = true
|
|
}
|
|
|
|
func findNavigationBarLineImageView(view:UIView?) -> UIImageView? {
|
|
guard let mai_new22View = view else { return nil }
|
|
if mai_new22View.isKind(of: UIImageView.self) && mai_new22View.bounds.size.height <= 1.0 {
|
|
return mai_new22View as? UIImageView
|
|
}
|
|
for maisubView33 in mai_new22View.subviews {
|
|
let maiimageViewmang = findNavigationBarLineImageView(view: maisubView33)
|
|
if (maiimageViewmang != nil) {
|
|
return maiimageViewmang
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|