获取当前屏幕显示的viewcontroller

来源:互联网 发布:俄罗斯残奥会禁赛知乎 编辑:程序博客网 时间:2024/05/21 09:58
#pragma mark 获取当前屏幕显示的viewcontroller/** *  @author zm *  @brief 获取当前屏幕显示的viewcontroller *  @return 当前的ViewController(未找到返回nil) */- (UIViewController *)f_getCurrentViewController{    UIViewController *_vc_result =nil;    UIWindow *_w_current = [[UIApplicationsharedApplication] keyWindow];    if (_w_current.windowLevel !=UIWindowLevelNormal)    {        NSArray *arr_windows = [[UIApplicationsharedApplication] windows];        for(UIWindow * _w_tempin arr_windows)        {            if (_w_temp.windowLevel ==UIWindowLevelNormal)            {               _w_current = _w_temp;                break;            }        }    }    UIView *_v_front = [[_w_currentsubviews] objectAtIndex:0];    id _id_nextResponder = [_v_frontnextResponder];        if ([_id_nextResponderisKindOfClass:[UIViewControllerclass]])        _vc_result = _id_nextResponder;    else        _vc_result = _w_current.rootViewController;    return _vc_result;}


8 0