//
|
// BaseNavigationController.swift
|
// BrokerDriver
|
//
|
// Created by 无故事王国 on 2023/4/24.
|
//
|
|
import UIKit
|
import JQTools
|
|
class BaseNav: UINavigationController,UINavigationControllerDelegate {
|
|
/// 需要透明Nav的VC
|
private var lucencyVCs = [LoginVC.self]
|
private var whiteStyleVCs = [HomeItemDetailVC.self,CourseDetialVC.self,CourseDetialVideoVC.self,PavilionDetailVC.self]
|
|
open override func viewDidLoad() {
|
super.viewDidLoad()
|
self.navigationBar.barTintColor = .red
|
self.navigationBar.tintColor = UIColor.black
|
self.navigationBar.shadowImage = UIImage()
|
self.navigationBar.isTranslucent = true
|
self.delegate = self
|
self.interactivePopGestureRecognizer?.delegate = self
|
|
|
if #available(iOS 15.0, *) {
|
let scrollBar = UINavigationBarAppearance()
|
scrollBar.configureWithOpaqueBackground()
|
scrollBar.backgroundEffect = nil
|
scrollBar.shadowColor = nil
|
scrollBar.titleTextAttributes = [.foregroundColor:Def_NavFontColor,.font:Def_NavFont]
|
scrollBar.backgroundColor = .white
|
|
let standardBar = UINavigationBarAppearance()
|
standardBar.configureWithOpaqueBackground()
|
standardBar.backgroundEffect = nil
|
standardBar.shadowColor = nil
|
standardBar.shadowImage = nil
|
standardBar.titleTextAttributes = [.foregroundColor:Def_NavFontColor,.font:Def_NavFont]
|
standardBar.backgroundColor = .white
|
|
navigationBar.scrollEdgeAppearance = scrollBar //顶部透明
|
navigationBar.standardAppearance = standardBar
|
}else {
|
navigationBar.titleTextAttributes = [.foregroundColor:Def_NavFontColor,.font:Def_NavFont]
|
navigationBar.isTranslucent = true
|
navigationBar.setBackgroundImage(UIImage(), for: .default)
|
navigationBar.shadowImage = UIImage()
|
}
|
}
|
|
open func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
|
|
var musicVC:PayMusicVC?
|
|
let showTree:Bool = viewController is TreeTeskVC
|
|
for vc in navigationController.tabBarController?.children ?? []{
|
if vc is PayMusicVC{
|
musicVC = (vc as! PayMusicVC);break
|
}
|
}
|
|
musicVC?.view.isHidden = (navigationController.viewControllers.count != 1 || showTree)
|
|
let status = lucencyVCs.contains(where: {$0 == viewController.classForCoder})
|
if (navigationController.viewControllers.count == 1 || status){
|
if #available(iOS 15.0, *) {
|
navigationBar.standardAppearance.backgroundColor = .clear
|
navigationBar.scrollEdgeAppearance?.backgroundColor = .clear
|
}else{
|
navigationBar.setBackgroundImage(UIImage(), for: .default)
|
navigationBar.shadowImage = UIImage()
|
}
|
}
|
|
|
if whiteStyleVCs.contains(where: {$0 == viewController.classForCoder}){
|
if #available(iOS 15.0, *) {
|
navigationBar.standardAppearance.titleTextAttributes = [.foregroundColor:UIColor.white,.font:Def_NavFont]
|
navigationBar.scrollEdgeAppearance?.titleTextAttributes = [.foregroundColor:UIColor.white,.font:Def_NavFont]
|
}else{
|
navigationBar.setBackgroundImage(UIImage(), for: .default)
|
navigationBar.shadowImage = UIImage()
|
}
|
}else{
|
navigationBar.standardAppearance.titleTextAttributes = [.foregroundColor:Def_NavFontColor,.font:Def_NavFont]
|
navigationBar.scrollEdgeAppearance?.titleTextAttributes = [.foregroundColor:Def_NavFontColor,.font:Def_NavFont]
|
}
|
|
|
if viewController is TreeTeskVC || viewController is HomeVC{
|
if #available(iOS 15.0, *) {
|
navigationBar.standardAppearance.backgroundColor = .white
|
navigationBar.scrollEdgeAppearance?.backgroundColor = .white
|
navigationBar.standardAppearance.titleTextAttributes = [.foregroundColor:UIColor.black,.font:Def_NavFont]
|
navigationBar.scrollEdgeAppearance?.titleTextAttributes = [.foregroundColor:UIColor.black,.font:Def_NavFont]
|
}else{
|
navigationBar.setBackgroundImage(UIImage(), for: .default)
|
navigationBar.shadowImage = UIImage()
|
}
|
}
|
}
|
|
//侧滑
|
public func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
|
if viewController == self.viewControllers[0] {
|
self.interactivePopGestureRecognizer!.delegate = self
|
}else{
|
self.interactivePopGestureRecognizer!.delegate = nil
|
}
|
}
|
|
// 是否支持自动转屏
|
override var shouldAutorotate: Bool {
|
return topViewController?.shouldAutorotate ?? false
|
}
|
|
// 支持哪些屏幕方向
|
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
return topViewController?.supportedInterfaceOrientations ?? .portrait
|
}
|
|
// 默认的屏幕方向(当前ViewController必须是通过模态出来的UIViewController(模态带导航的无效)方式展现出来的,才会调用这个方法)
|
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
|
return topViewController?.preferredInterfaceOrientationForPresentation ?? .portrait
|
}
|
|
open override var childForStatusBarHidden: UIViewController? {
|
return self.topViewController
|
}
|
|
open override var childForStatusBarStyle: UIViewController? {
|
return self.topViewController
|
}
|
|
override var preferredStatusBarStyle: UIStatusBarStyle{
|
return .lightContent
|
}
|
|
}
|
|
|
class LoginNav: UINavigationController,UINavigationControllerDelegate {
|
|
private var popDelegate: UIGestureRecognizerDelegate?
|
/// 需要透明Nav的VC
|
private var lucencyVCs = [LoginVC.self,BackgroundVoiceVC.self]
|
|
open override func viewDidLoad() {
|
super.viewDidLoad()
|
self.navigationBar.barTintColor = .white
|
self.navigationBar.titleTextAttributes = [.font:UIFont.systemFont(ofSize: 18, weight: .medium), .foregroundColor:UIColor.black]
|
self.navigationBar.tintColor = UIColor.black
|
self.navigationBar.shadowImage = UIImage()
|
self.navigationBar.isTranslucent = true
|
self.delegate = self
|
self.popDelegate = self.interactivePopGestureRecognizer?.delegate
|
|
|
if #available(iOS 15.0, *) {
|
let scrollBar = UINavigationBarAppearance()
|
scrollBar.configureWithOpaqueBackground()
|
scrollBar.backgroundEffect = nil
|
scrollBar.shadowColor = nil
|
scrollBar.titleTextAttributes = [.foregroundColor:Def_NavFontColor,.font:Def_NavFont]
|
scrollBar.backgroundColor = UIColor.clear
|
|
|
let standardBar = UINavigationBarAppearance()
|
standardBar.configureWithOpaqueBackground()
|
standardBar.backgroundEffect = nil
|
standardBar.shadowColor = nil
|
standardBar.shadowImage = nil
|
standardBar.titleTextAttributes = [.foregroundColor:Def_NavFontColor,.font:Def_NavFont]
|
standardBar.backgroundColor = UIColor.clear
|
|
navigationBar.scrollEdgeAppearance = scrollBar //顶部透明
|
navigationBar.standardAppearance = standardBar
|
|
|
}else {
|
navigationBar.titleTextAttributes = [.foregroundColor:Def_NavFontColor,.font:Def_NavFont]
|
}
|
}
|
|
open func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
|
let status = lucencyVCs.contains(where: {$0 == viewController.classForCoder})
|
if (navigationController.viewControllers.count == 1 || status){
|
if #available(iOS 15.0, *) {
|
navigationBar.standardAppearance.backgroundColor = .clear
|
navigationBar.scrollEdgeAppearance?.backgroundColor = .clear
|
}else{
|
navigationBar.setBackgroundImage(UIImage(), for: .default)
|
navigationBar.shadowImage = UIImage()
|
}
|
}
|
|
}
|
|
//侧滑
|
public func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
|
if viewController == self.viewControllers[0] {
|
self.interactivePopGestureRecognizer!.delegate = self.popDelegate
|
}else{
|
self.interactivePopGestureRecognizer!.delegate = nil
|
}
|
}
|
|
open override var childForStatusBarHidden: UIViewController? {
|
return self.topViewController
|
}
|
|
open override var childForStatusBarStyle: UIViewController? {
|
return self.topViewController
|
}
|
|
}
|