Created
June 1, 2016 09:19
-
-
Save yunyang088/3d09865da73747df415ad3b74eb90066 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//获取当前屏幕显示的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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment