iOS 获取当前正在显示的ViewController
2016-07-29 17:10
435 查看
//获取当前屏幕显示的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;
}
测试可以使用
- (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;
}
测试可以使用
相关文章推荐
- iOS开发之初:自定义tabBar与tabBarController
- OC学习日记01
- iOS项目的完整重命名方法图文教程
- ios之NSUserDefault存储自定义类型的对象
- IOS线程间通信
- iOS中关于旋转屏的控制
- iOS中关于旋转屏的控制
- ios获取文件目录方法
- iOS 下ARC的内存管理机制
- ios获取当前时间年月日时分秒
- iOS设计模式-原型模式
- 浅谈 iOS 版本号
- iOS应用程序5种常见的存储方式
- iOS电池的监听
- iOS -- 上传图片到服务器
- [编写高质量iOS代码的52个有效方法](十一)系统框架
- iOS 简单实现抽屉效果
- iOS图像处理之 coreImage.
- 二维码扫描
- iOS开发设置关于tabBar和navigationBar以及item中的一些全局属性