- (UIViewController *)getCurrentVC
{
UIViewController * curVC = 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]])
{
curVC = nextResponder;
}
else
{
UIViewController * appRootVC = window.rootViewController;
UIViewController * topVC = appRootVC;
curVC = topVC;
if (topVC.presentedViewController)
{
curVC = topVC.presentedViewController;
}
}
return curVC;
}获取iOS应用中当前处于Activity状态的ViewController
最新推荐文章于 2025-11-09 15:06:28 发布
本文提供了一个Objective-C方法,用于从iOS应用中获取当前显示的UIViewController。该方法首先确定正常层级窗口,然后通过响应链找到最上层的ViewController。如果未找到,则会检查根ViewController及其可能存在的Presented ViewController。
728

被折叠的 条评论
为什么被折叠?



