key window蒙层

注意点

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];

  

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值