+ (UIViewController *)getCurView {
UIViewController *currentViewController = 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]])
currentViewController = nextResponder;
else
currentViewController = window.rootViewController;
while ([currentViewController presentedViewController]) {
currentViewController = [currentViewController presentedViewController];
if ([currentViewController isKindOfClass:[UINavigationController class]]) {
currentViewController = [(UINavigationController *)currentViewController visibleViewController];
NSLog(@"%@",[currentViewController class]);
}
}
return currentViewController;
}
@end
网友评论