关于带透明度的灰度层的show、hide

时间:2022-11-29 05:57:50

原理图如下:【需要注意的是,灰度View与中间的小View是并列的关系,否则,带透明度的灰度图就会影响小View的透明度】

关于带透明度的灰度层的show、hide

- (void)show{

UIWindow *win = [[UIApplication sharedApplication] keyWindow];

UIView *topView = [win.subviews objectAtIndex:0];

[topView addSubview:self];

[UIView animateWithDuration:0.1 animations:^{

[self layoutIfNeeded];

}];

}

- (void)hide{

[UIView animateWithDuration:0.1 animations:^{

self.alpha = 0;

[self layoutIfNeeded];

} completion:^(BOOL finished) {

[self removeFromSuperview];

}];

}