NYWindow.swift 674 B

123456789101112131415161718192021222324252627
  1. //
  2. // NYWindow.swift
  3. // JiaPeiManage
  4. //
  5. // Created by Ning.ge on 2023/8/3.
  6. //
  7. import UIKit
  8. struct NYWindow {
  9. ///获取当前控制器
  10. static func currentVc() ->UIViewController{
  11. var vc = UIApplication.shared.keyWindow?.rootViewController
  12. if (vc?.isKind(of: UITabBarController.self))! {
  13. vc = (vc as! UITabBarController).selectedViewController
  14. }else if (vc?.isKind(of: UINavigationController.self))!{
  15. vc = (vc as! UINavigationController).visibleViewController
  16. }else if ((vc?.presentedViewController) != nil){
  17. vc = vc?.presentedViewController
  18. }
  19. return vc!
  20. }
  21. }