Browse Source

Merge branch 'master' of https://git.yishihui.com/iOS/BFCommonKit

# Conflicts:
#	BFCommonKit/Classes/BFConfig/PQBFConfig.swift
合并代码
jsonwang 3 years ago
parent
commit
830a1407b9
1 changed files with 31 additions and 0 deletions
  1. 31 0
      BFCommonKit/Classes/BFUtility/PQCommonMethodUtil.swift

+ 31 - 0
BFCommonKit/Classes/BFUtility/PQCommonMethodUtil.swift

@@ -15,6 +15,7 @@ import KingfisherWebP
 import Photos
 import Toast_Swift
 import RealmSwift
+import UIKit
 
 /// Home文件地址
 public let homeDirectory = NSHomeDirectory()
@@ -132,6 +133,36 @@ public func kf_imageCacheImage(originUrl: String, completeHandle: @escaping (_ i
     }
 }
 
+public func bf_getRootViewController() -> UIViewController? {
+    guard let window = UIApplication.shared.delegate?.window else {
+        return nil
+    }
+    return window!.rootViewController
+}
+
+public func bf_getCurrentViewController() -> UIViewController? {
+    var currentVC = bf_getRootViewController()
+    if currentVC == nil {
+        return nil
+    }
+    
+    let runloopFind = true
+    while runloopFind {
+        if let vc = currentVC!.presentedViewController {
+            currentVC = vc
+        }else {
+            if currentVC is UINavigationController {
+                currentVC = (currentVC as! UINavigationController).visibleViewController
+            }else if currentVC is UITabBarController {
+                currentVC = (currentVC as! UITabBarController).selectedViewController
+            }else {
+                break
+            }
+        }
+    }
+    return currentVC
+}
+
 
 /** 打印
    type = 1 : 胡志强