美文网首页
iOS获取当前显示最顶层的ViewController

iOS获取当前显示最顶层的ViewController

作者: Macanzy | 来源:发表于2019-10-21 20:02 被阅读0次
    - (UIViewController*)currentViewController{
        UIViewController* vc = [UIApplication sharedApplication].keyWindow.rootViewController;
        while (true) {
            if ([vc isKindOfClass:[UINavigationController class]]) {
                vc = [(UINavigationController *)vc visibleViewController];
            } else if ([vc isKindOfClass:[UITabBarController class]]) {
                vc = [(UITabBarController *)vc selectedViewController];
            } else if (vc.presentedViewController) {
                vc = vc.presentedViewController;
            }else {
                break;
            }
        }
        return vc;
    }
    

    相关文章

      网友评论

          本文标题:iOS获取当前显示最顶层的ViewController

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