Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Scene/Share/NavigationController/AdaptiveStatusBarStyleNavig...

41 lines
1.4 KiB
Swift
Raw Normal View History

2021-04-01 08:39:15 +02:00
//
// AdaptiveStatusBarStyleNavigationController.swift
//
//
// Created by MainasuK Cirno on 2021-2-26.
//
import UIKit
// Make status bar style adptive for child view controller
// SeeAlso: `modalPresentationCapturesStatusBarAppearance`
final class AdaptiveStatusBarStyleNavigationController: UINavigationController {
var viewControllersHiddenNavigationBar: [UIViewController.Type]
2021-04-01 08:39:15 +02:00
override var childForStatusBarStyle: UIViewController? {
visibleViewController
}
override init(rootViewController: UIViewController) {
self.viewControllersHiddenNavigationBar = [SearchViewController.self]
super.init(rootViewController: rootViewController)
self.delegate = self
}
@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension AdaptiveStatusBarStyleNavigationController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
let isContain = self.viewControllersHiddenNavigationBar.contains { type(of: viewController) == $0 }
if isContain {
self.setNavigationBarHidden(true, animated: animated)
} else {
self.setNavigationBarHidden(false, animated: animated)
}
2021-04-01 08:39:15 +02:00
}
}