IOS理论知识

根据自己项目获取到的当前控制器

2017-01-04  本文已影响7人  IceWall_Rin

+ (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

上一篇下一篇

猜你喜欢

热点阅读