iOS如何优雅的设置后台毛玻璃效果

2020-05-14  本文已影响0人  桥下醉翁

App在进入后台后,需要使用毛玻璃效果遮盖

@property (nonatomic, strong) UIVisualEffectView *visualView;


- (void)applicationWillResignActive:(UIApplication *)application {
    if (!self.visualView) {
        UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        self.visualView = [[UIVisualEffectView alloc] initWithEffect:blur];
        self.visualView.alpha = 0;
        self.visualView.frame = self.window.frame;
        [self.window addSubview:self.visualView];
    }
    // 页面转场会出现bug,简单修复下
    [self.window bringSubviewToFront:self.visualView];
    [UIView animateWithDuration:0.5 animations:^{
        self.visualView.alpha = 1;
    }];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    if (self.visualView) {
        [UIView animateWithDuration:0.5 animations:^{
            self.visualView.alpha = 0;
        }];
    }
}

上一篇下一篇

猜你喜欢

热点阅读