您的位置:首页 > 其它

获取当前屏幕显示的viewcontroller

2016-06-03 15:30 363 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: