原理图如下:【需要注意的是,灰度View与中间的小View是并列的关系,否则,带透明度的灰度图就会影响小View的透明度】
- (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];
}];
}