AppDelegate.m文件
//懒加载一个毛玻璃效果 UIVisualEffectView
- (UIVisualEffectView *)effectView {
if (!_effectView) {
// 初始毛玻璃view
_effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
// 模糊透明度
_effectView.alpha = 0.9;
_effectView.frame = [UIScreen mainScreen].bounds;
}
return _effectView;
}
//添加 UIVisualEffectView
-(void)addEffectView {
[[[UIApplication sharedApplication] keyWindow] addSubview:self.effectView];
}
//移除 UIVisualEffectView
-(void) removeEffectView {
[UIView animateWithDuration:0.5 animations:^{
[self.effectView removeFromSuperview];
}];
}
//执行 添加方法
- (void)applicationWillResignActive:(UIApplication *)application {
self.addEffectView();
}
//执行 移除方法
- (void)applicationDidBecomeActive:(UIApplication *)application{
self.removeEffectView();
}