You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

95 lines
3.5 KiB

//
// NavigationController.swift
// Lookfit
//
// Created by lemo. on 2020/3/7.
// Copyright © 2020 Sheldon. All rights reserved.
//
import UIKit
class NavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
LFLogs("init: \(type(of: self))")
makeUI()
//
self.interactivePopGestureRecognizer?.delegate = self
}
override var preferredStatusBarStyle: UIStatusBarStyle {
let viewController = self.viewControllers.last as? ViewController
let isLightStatusBar = viewController?.isLightStatusBar ?? false
if #available(iOS 13.0, *) {
return isLightStatusBar ? .lightContent : .darkContent
} else {
return isLightStatusBar ? .lightContent : .default
}
}
func makeUI() {
//
navigationBar.setBackgroundImage(UIImage.color(ThemeManager.commonBgColor), for: UIBarPosition.any, barMetrics: .default)
navigationBar.shadowImage = UIImage()
//
let bar = UINavigationBar.appearance()
bar.titleTextAttributes = [
NSAttributedString.Key.foregroundColor : ThemeManager.commonTextColor,
NSAttributedString.Key.font: ThemeManager.navBarFont]
// 线
if let backgroundView = navigationBar.subviews.first {
backgroundView.subviews.forEach { (view) in
if view.height <= 1 {
view.isHidden = true
}
}
}
if #available(iOS 15, *) {
let app = UINavigationBarAppearance.init()
app.configureWithOpaqueBackground() //
app.titleTextAttributes = [
NSAttributedString.Key.font: ThemeManager.navBarFont,
NSAttributedString.Key.foregroundColor: ThemeManager.commonTextColor
]
app.backgroundColor = ThemeManager.commonBgColor //
app.shadowImage = UIImage() // 线
navigationBar.scrollEdgeAppearance = app // scroll
navigationBar.standardAppearance = app //
}
}
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
//
if children.count > 0, let vc = viewController as? ViewController {
let leftItems = UIBarButtonItem.baseBarButtonItem(normalImg: "nav_back", highImg: "nav_back", title: vc.navigationTitle, target: self, action: #selector(clickBack))
vc.navigationItem.leftBarButtonItem = leftItems
vc.hidesBottomBarWhenPushed = true
}
super.pushViewController(viewController, animated: animated)
}
@objc func clickBack() {
self.popViewController(animated: true)
}
deinit {
LFLogs("deinit: \(type(of: self))")
}
}
// MARK: -
extension NavigationController: UIGestureRecognizerDelegate {
///
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
let isRootVC = self.viewControllers.count > 1
return isRootVC
}
///
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
view.endEditing(true)
}
}