iOS app切换后台时添加模糊遮罩层

仿 支付宝 退出后台后,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;

添加相对应的代码即可.

相关推荐

  1. iOS app切换后台添加模糊

    2023-12-09 06:40:02       39 阅读
  2. android中给view添加

    2023-12-09 06:40:02       9 阅读
  3. vue3 | 自定义组件

    2023-12-09 06:40:02       31 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-09 06:40:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-09 06:40:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-09 06:40:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-09 06:40:02       18 阅读

热门阅读

  1. Python函数的参数

    2023-12-09 06:40:02       42 阅读
  2. 128.最长连续子序列

    2023-12-09 06:40:02       29 阅读
  3. SQLite基本使用

    2023-12-09 06:40:02       37 阅读
  4. redis中序列化问题,value包含全路径类名解析

    2023-12-09 06:40:02       32 阅读
  5. ALLEGRO PCB 如何设置增加的过孔

    2023-12-09 06:40:02       37 阅读
  6. GDS Configuration File Changes to Support Dynamic Routing

    2023-12-09 06:40:02       42 阅读
  7. golang开发一个聊天系统例子

    2023-12-09 06:40:02       40 阅读
  8. HTML5 基础总结

    2023-12-09 06:40:02       43 阅读
  9. Qt OpenCV 学习(六):kmeans聚类算法实现背景替换

    2023-12-09 06:40:02       33 阅读
  10. 云计算ACP认证考试题库0-100

    2023-12-09 06:40:02       36 阅读
  11. ssh框架原理及流程

    2023-12-09 06:40:02       38 阅读