iOS 获取当前展示的页面
Posted 阳光普照大地
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS 获取当前展示的页面相关的知识,希望对你有一定的参考价值。
- - (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;
- }
- - (UIViewController *)getPresentedViewController
- {
- UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
- UIViewController *topVC = appRootVC;
- if (topVC.presentedViewController) {
- topVC = topVC.presentedViewController;
- }
- return topVC;
- }
以上是关于iOS 获取当前展示的页面的主要内容,如果未能解决你的问题,请参考以下文章
微信小程序获取轮播图当前图片下标滑动展示对应的位数点击位数展示对应图片
iOS开发 - 获取当前View最顶层的ViewController