iOS添加遮罩层

来源:互联网 发布:蓝牙数据写到 mic 编辑:程序博客网 时间:2024/06/07 23:38

添加遮罩层的原理是在一个可以操作的UIView下面有另一个UIView,下边的UIView的作用是遮挡住页面,使其无法进行操作,直到前一个界面的操作结束,然后直接将后一个UIView移除,代码如下:
[UIView animateWithDuration:0.4 animations:^{

    int iconWidth=delegate.currentWidth/2;    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(iconWidth-60,140,150,105 )];    [view setBackgroundColor:[UIColor colorWithRed:255.f/255.f green:255.f/255.f blue:255.f/255.f alpha:1]];    view.layer.cornerRadius=10;    view.backgroundColor = [UIColor colorWithRed:255. green:55. blue:255. alpha:0.89f];    view.layer.borderColor = [[UIColor lightGrayColor] CGColor];    view.layer.borderWidth = 2.0f;    //view.layer.cornerRadius = 10.0f;    view.clipsToBounds = YES;    view1 = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    //view1.backgroundColor = [UIColor colorWithRed:.255 green:.255 blue:.0 alpha:.255];    [view1 setBackgroundColor:[UIColor whiteColor]];    [view1 setAlpha:0.2];

[UIView animateWithDuration:.8 animations:^{
[self->addRenTV addSubview:view1];//addRenTV是主界面
}];
[view1 addSubview:view];
self->addRenTV.scrollEnabled = NO;
}];
* 其中,view1是下边的,所以移除时要移除view1,这也是为什么要把它定义成全局变量,如果在其他函数里实现移除就可以直接写:
[view1 removeFromSuperview];