Xcode SceneDelegate.swift 场景代理文件(窗口的生命周期)

SceneDelegate.swift 场景代理文件

SceneDelegate.swift 场景代理文件 用来管理应用程序的多个场景,以及管理用户界面的生命周期。

 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        guard let _ = (scene as? UIWindowScene) else { return }
    }

可以把场景载入后需要执行的代码,写在willConnectTo的方法里面。

** func sceneDidDisconnect(_ scene: UIScene) {}**

场景被系统释放时,调用 sceneDidDisconnect 方法,在场景进入背景后不久,或会话被丢弃时发生。

func sceneDidBecomeActive(_ scene: UIScene) {}

场景从非活动状态转换为活动状态时,调用sceneDidBecomeActive 方法,可以在这个方法中,重启场景处于非活动状态时已暂停的任务。

 func sceneWillResignActive(_ scene: UIScene) {}

场景将从活动状态转换为非活动状态时,调用sceneWillResignActive方法,这可能是由于临时中断而发生的,比如,有电话打入的时候。

func sceneWillEnterForeground(_ scene: UIScene) {
        // Called as the scene transitions from the background to the foreground.
        // Use this method to undo the changes made on entering the background.
    }

在场景从背景过渡到前景时,执行该方法。使用这个方法,可以撤消在进入背景时所做的更改。

func sceneDidEnterBackground(_ scene: UIScene) {
        // Called as the scene transitions from the foreground to the background.
        // Use this method to save data, release shared resources, and store enough scene-specific state information
        // to restore the scene back to its current state.
    }

在场景从前景过渡到背景时,调用此方法。用此方法可以保存数据,释放共享资源,或者存储场景的状态信息。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值