/** 递归查找当前显示的VC*/
+ (UIViewController *)recursiveFindCurrentShowViewControllerFromViewController:(UIViewController *)fromVC
{
if ([fromVC isKindOfClass:[UINavigationController class]]) {
return [self recursiveFindCurrentShowViewControllerFromViewController:[((UINavigationController *)fromVC) visibleViewController]];
} else if ([fromVC isKindOfClass:[UITabBarController class]]) {
return [self recursiveFindCurrentShowViewControllerFromViewController:[((UITabBarController *)fromVC) selectedViewController]];
} else {
if (fromVC.presentedViewController) {
return [self recursiveFindCurrentShowViewControllerFromViewController:fromVC.presentedViewController];
} else {
return fromVC;
}
}
}
/** 查找当前显示的ViewController*/
+ (UIViewController *)getCurrentShowViewController
{
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *currentShowVC = [self recursiveFindCurrentShowViewControllerFromViewController:rootVC];
return currentShowVC;
}
摘自:https://blog.csdn.net/weixin_34242509/article/details/93697460
网友评论