注意点
1.[[UIApplication sharedApplication]keyWindow]放在点击事件方法里面获取
2.设置一个view作为蒙层将alpha设置0.5 将其添加在key window上 然后载将想要展示的控件添加在keywindow上 等于跟蒙层同一个层次将蒙层压在下面。
- (IBAction)btn:(id)sender {
UIWindow *currentWindow = [[UIApplication sharedApplication]keyWindow];
//蒙层view
UIView *vv = [[UIView alloc]initWithFrame:self.view.frame]; vv.backgroundColor = [UIColor purpleColor];
vv.alpha = 0.5;
[currentWindow addSubview:vv];
//展示的view
UIView *vv2 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
vv2.backgroundColor = [UIColor redColor];
[currentWindow addSubview:vv2];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
btn2.frame = CGRectMake(0, 0, 50, 50);
btn2.backgroundColor = [UIColor blueColor];
[btn2 addTarget:self action:@selector(aa) forControlEvents:(UIControlEventTouchUpInside)];
[vv2 addSubview:btn2];
}