在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
extension UIViewController { /// 获取当前显示的VC /// /// - Returns: 当前屏幕显示的VC class func getCurrentViewController() -> UIViewController?{ // 获取当先显示的window var currentWindow = UIApplication.shared.keyWindow ?? UIWindow() if currentWindow.windowLevel != UIWindow.Level.normal { let windowArr = UIApplication.shared.windows for window in windowArr { if window.windowLevel == UIWindow.Level.normal { currentWindow = window break } } } return UIViewController.getNextXController(nextController: currentWindow.rootViewController) } private class func getNextXController(nextController: UIViewController?) -> UIViewController? { if nextController == nil { return nil }else if nextController?.presentedViewController != nil { return UIViewController.getNextXController(nextController: nextController?.presentedViewController) }else if let tabbar = nextController as? UITabBarController { return UIViewController.getNextXController(nextController: tabbar.selectedViewController) }else if let nav = nextController as? UINavigationController { return UIViewController.getNextXController(nextController: nav.visibleViewController) } return nextController } }
|
请发表评论