class public func getCurrentVc() -> UIViewController{
let rootVc = UIApplication.shared.keyWindow?.rootViewController
let currentVc =getCurrentVcFrom(rootVc!)
return currentVc
}
class private func getCurrentVcFrom(_ rootVc:UIViewController) -> UIViewController{
var currentVc:UIViewController
var rootCtr = rootVc
if (rootCtr.presentedViewController != nil) {
rootCtr = rootVc.presentedViewController!
}
if rootVc.isKind(of:UITabBarController.classForCoder()) {
currentVc = getCurrentVcFrom((rootVcas!UITabBarController).selectedViewController!)
}else if rootVc.isKind(of:UINavigationController.classForCoder()){
currentVc = getCurrentVcFrom((rootVcas!UINavigationController).visibleViewController!)
}else{
currentVc = rootCtr
}
return currentVc
}
网友评论