zoukankan      html  css  js  c++  java
  • swift 获取当前显示的VC

    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
        }
    }
  • 相关阅读:
    NYOJ--703
    CDOJ--1369
    NYOJ--205
    NYOJ--520
    NYOJ--69
    CDOJ--1237
    [gist]Android SHA-1
    ConnectionAbortedError: [WinError 10053] 你的主机中的软件中止了一个已建立的连接
    SyntaxError:unexpected EOF while parsing(<string,line 0>)
    Django之get请求url的参数
  • 原文地址:https://www.cnblogs.com/qingzZ/p/12509511.html
Copyright © 2011-2022 走看看