UIWindow介绍

创建一个Window

1
2
3
4
5
6
UIWindow *greenWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
greenWindow.windowLevel = UIWindowLevelStatusBar;
greenWindow.backgroundColor = [UIColor greenColor];
greenWindow.alpha = 0.3;
// default hidden=YES
greenWindow.hidden = NO;

这样greenWindow就已经放在屏幕上显示了

隐藏Window

1
2
greenWindow.hidden = YES;
greenWindow = nil;

给Window添加单击事件

1
2
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:selector(greenWindowTapped:)];
[greenWindow addGestureRecognizer:tap];