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

原理图如下:【需要注意的是,灰度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];

    }];

}

原文地址:https://www.cnblogs.com/lrr0618/p/5346119.html