此代码在iOS 12上运行良好- 问题出在iOS 13+ 我知道这与iOS 13场景有关。
extension UIViewController {
static var top: UIViewController? {
get {
return topViewController()
}
}
static var root: UIViewController? {
get {
return UIApplication.shared.windows[0].rootViewController
}
}
static func topViewController(from viewController: UIViewController? = UIViewController.root) -> UIViewController? {
if let tabBarViewController = viewController as? UITabBarController {
return topViewController(from: tabBarViewController.selectedViewController)
} else if let navigationController = viewController as? UINavigationController {
return topViewController(from: navigationController.visibleViewController)
} else if let presentedViewController = viewController?.presentedViewController {
return topViewController(from: presentedViewController)
} else {
return viewController
}
}
}
当我使用iOS 12获得UIViewController.top
时,一切正常,但在iOS 13中为零。
任何想法如何解决?