56 lines
1.6 KiB
Swift
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
|
|
}
|
|
}
|
|
}
|