ios-获取当前正在显示的ViewController
2015-09-07 18:11
495 查看
我们在非视图类中想要随时展示一个view时,需要将被展示的view加到当前view的子视图,或用当前view presentViewController,或pushViewContrller,这些操作都需要获取当前正在显示的ViewController。
//获取当前屏幕显示的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; }
相关文章推荐
- ios学习笔记(3)
- 复杂版计算器的实现
- IOS学习笔记 ---- 15/09/07
- iOS开发系列课程(04) --- 文本框和视图控制器
- iOS小结(三)animation blocks VS CALayer animation
- 解决IOS8上无法创建同名删除相册的问题
- iOS旋屏控制
- IOS Certificates, Identifiers, Devices, Profiles
- IOS_OC_字典
- iOS开发笔记之ViewController视图控制器间的跳转
- ios 文件上传
- IOS_oc 数组
- ios工程依赖
- iOS越狱的判定方法
- iOS开发者有价值的工具集
- ios 界面间跳转方法总结
- iOS开发——Block循环引用问题的解决
- ios开发出现 -[__NSDictionaryM isEqualToString:]: unrecognized selector sent to instance 错误
- iOS开发-获取子视图坐标系中Point、Rect在父视图坐标系中的实际值
- 《IOS_OC》继承、多态、初始化方法、便利构造器