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.
}
在场景从前景过渡到背景时,调用此方法。用此方法可以保存数据,释放共享资源,或者存储场景的状态信息。