key window蒙层

来源:互联网 发布:游戏编程入门 道森 pdf 编辑:程序博客网 时间:2024/05/22 00:05

注意点

1.[[UIApplication sharedApplication]keyWindow]放在点击事件方法里面获取

2.设置一个view作为蒙层将alpha设置0.5  将其添加在key window上   然后载将想要展示的控件添加在keywindow上  等于跟蒙层同一个层次将蒙层压在下面。  


- (IBAction)btn:(id)sender {

    UIWindow *currentWindow = [[UIApplicationsharedApplication]keyWindow];

    //蒙层view

    UIView *vv = [[UIViewalloc]initWithFrame:self.view.frame];    vv.backgroundColor = [UIColorpurpleColor];

    vv.alpha = 0.5;

    [currentWindow addSubview:vv];

    

    

    //展示的view

    UIView *vv2 = [[UIViewalloc]initWithFrame:CGRectMake(100,100, 100,100)];

    vv2.backgroundColor = [UIColorredColor];

    [currentWindow addSubview:vv2];

    UIButton *btn2 = [UIButtonbuttonWithType:UIButtonTypeCustom];

    btn2.frame = CGRectMake(0,0, 50,50);

    btn2.backgroundColor = [UIColorblueColor];

    [btn2 addTarget:selfaction:@selector(aa)forControlEvents:(UIControlEventTouchUpInside)];

    [vv2 addSubview:btn2];

  

}

0 0
原创粉丝点击