美文网首页
iOS - 获取当前展示的VC

iOS - 获取当前展示的VC

作者: HanZhiZzzzz | 来源:发表于2020-04-03 17:32 被阅读0次

    /** 递归查找当前显示的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

    相关文章

      网友评论

          本文标题:iOS - 获取当前展示的VC

          本文链接:https://www.haomeiwen.com/subject/khskphtx.html