ios开发之--找window,获取屏幕最上层的窗口
1、delegate
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
2、windows
获取当前最顶层的窗口
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
在实际需求中,讲某一UIView控件添加到最上层,可以考虑获取当前顶层的窗口来添加UIView控件,代码如下:
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 300)]; aView.backgroundColor = [UIColor redColor]; // 当前顶层窗口 UIWindow *window = [[UIApplication sharedApplication].windows lastObject]; // 添加到窗口 [window addSubview:aView];
仅做记录!
本文来自博客园,作者:稻草人11223,转载请注明原文链接:https://www.cnblogs.com/hero11223/p/12295143.html