zoukankan      html  css  js  c++  java
  • 获取当前屏幕显示的viewcontroller

    //获取当前屏幕显示的viewcontroller 

    - (UIViewController *)getCurrentVC 
        UIViewController *result = nil
           
        UIWindow * window = [[UIApplication sharedApplication] keyWindow]; 
        if (window.windowLevel != UIWindowLevelNormal) 
        
            NSArray *windows = [[UIApplication sharedApplication] windows]; 
            for(UIWindow * tmpWin in windows) 
            
                if (tmpWin.windowLevel == UIWindowLevelNormal) 
                
                    window = tmpWin; 
                    break; 
                
            
        
           
        UIView *frontView = [[window subviews] objectAtIndex:0]; 
        id nextResponder = [frontView nextResponder]; 
           
        if ([nextResponder isKindOfClass:[UIViewController class]]) 
            result = nextResponder; 
        else 
            result = window.rootViewController
           
        return result; 
    }
  • 相关阅读:
    CocoaPods 安装教程
    iOS 如何使用第三方字库
    iOS 获取当前网络状态
    GitHub上README.md教程
    如何获取iOS软件包内容
    iOS中如何监测来电
    OS 如何选择delegate、notification、KVO?
    iOS-Block总结 && 全面解析逆向传值
    iOS面试题
    iOS优秀博客收录
  • 原文地址:https://www.cnblogs.com/-ios/p/4669734.html
Copyright © 2011-2022 走看看