IOS获取当前页面的控制器
2019-02-22 本文已影响0人
向日葵的夏天_summer
获取当前页面所属的控制器代码:
//MARK:- 获取当前控制器
static func getCurrentVC() -> UIViewController {
var vc = UIApplication.shared.keyWindow?.rootViewController
while(true) {
if (vc?.isKind(of: UITabBarController.self))! {
vc = (vc as! UITabBarController).selectedViewController
}else if (vc?.isKind(of: UINavigationController.self))!{
vc = (vc as! UINavigationController).visibleViewController
}else if ((vc?.presentedViewController) != nil){
vc = vc?.presentedViewController
} else {
break
}
}
return vc!
}