「SwiftUI」关于Navigation

navigation 自定义处理

Posted by Jiaolong on 2021/09/04

Basic

Custom

extension UINavigationController {
    override open func viewDidLoad() {
        super.viewDidLoad()
        let coloredAppearance = UINavigationBarAppearance()
        coloredAppearance.configureWithOpaqueBackground()
        coloredAppearance.backgroundColor = UIColor(Color.blue)     //背景颜色
        coloredAppearance.titleTextAttributes = [.foregroundColor: UIColor(Color.blue)] //大标题颜色
        coloredAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor(Color.blue)]
        UINavigationBar.appearance().standardAppearance = coloredAppearance
        UINavigationBar.appearance().compactAppearance = coloredAppearance
        UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
        UINavigationBar.appearance().tintColor =  UIColor(Color.blue)   //左上角返回标记
    }
}

隐藏navigationBar

UINavigationBar.appearance().isHidden = true  //可以右滑返回
.navigationBarHidden(true)//不能右滑返回

修正侧滑返回失效问题

import SwiftUI
import Foundation

//修正侧滑返回
extension UINavigationController: UIGestureRecognizerDelegate {
    override open func viewDidLoad() {
        super.viewDidLoad()
        interactivePopGestureRecognizer?.delegate = self
    }
    public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        return viewControllers.count > 1
    }
}