BeeReel/BeeReel/Lib/AppTool/BRAppTool.swift
2025-06-30 18:18:27 +08:00

56 lines
1.6 KiB
Swift

//
// BRAppTool.swift
// BeeReel
//
// Created by on 2025/6/24.
//
import UIKit
class BRAppTool {
static var appDelegate: AppDelegate?
static var sceneDelegate: SceneDelegate?
static var windowScene: UIWindowScene?
static var keyWindow: UIWindow? {
return windowScene?.keyWindow
}
static var rootViewController: UIViewController? {
return keyWindow?.rootViewController
}
///
static var lanuchViewController: UIViewController? {
let storyboard = UIStoryboard(name: "LaunchScreen", bundle: nil)
let vc = storyboard.instantiateInitialViewController()
return vc
}
static var topViewController: UIViewController? {
var resultVC: UIViewController? = self.rootViewController
if let rootNav = resultVC as? UINavigationController {
resultVC = rootNav.topViewController
}
resultVC = self._topViewController(resultVC)
while resultVC?.presentedViewController != nil {
resultVC = self._topViewController(resultVC?.presentedViewController)
}
return resultVC
}
private static func _topViewController(_ vc: UIViewController?) -> UIViewController? {
if vc is UINavigationController {
return _topViewController((vc as? UINavigationController)?.topViewController)
} else if vc is UITabBarController {
return _topViewController((vc as? UITabBarController)?.selectedViewController)
} else {
return vc
}
}
}