仿 支付寶 退出后臺后,App整個 增加模糊遮罩層
此處只介紹 在iOS13后?SceneDelegate 下的操作
原理就是
在?App 進入后臺后 在 主window上添加一個 ?UIVisualEffectView
在進入前臺后移除
直接上代碼:
先聲明:
//先聲明
/* blurView */
@property (strong, nonatomic) UIVisualEffectView *blurView;
在代理方法中:
- (void)sceneDidBecomeActive:(UIScene *)scene;
- (void)sceneWillResignActive:(UIScene *)scene;
- (void)sceneDidBecomeActive:(UIScene *)scene {// Called when the scene has moved from an inactive state to an active state.// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.if (_blurView) {[_blurView removeFromSuperview];}
}- (void)sceneWillResignActive:(UIScene *)scene {// Called when the scene will move from an active state to an inactive state.// This may occur due to temporary interruptions (ex. an incoming phone call).if(!_blurView) {UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];_blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];_blurView.frame = self.window.bounds;}//進入后臺實現模糊效果[self.window addSubview:_blurView];
}
收工,
如果沒有SceneDelegate ,只有AppDelegate
同理在
- (void)applicationDidBecomeActive:(UIApplication *)application;
- (void)applicationWillResignActive:(UIApplication *)application;
添加相對應的代碼即可.