iOS新增遮罩層
阿新 • • 發佈:2018-11-03
新增遮罩層的原理是在一個可以操作的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];