我为这样的暂停视图创建launchScreen。
func applicationWillResignActive(_ application: UIApplication) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let launchScreen = storyboard.instantiateViewController(withIdentifier: "launchScreen")
launchScreen.restorationIdentifier = "launchScreen"
var rootViewController = UIApplication.shared.keyWindow?.rootViewController
while let presentController = rootViewController?.presentedViewController {
rootViewController = presentController
}
rootViewController?.present(launchScreen, animated: false, completion: nil)
}
func applicationDidEnterBackground(_ application: UIApplication) {
guard let passcodeManageView = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "passcodeManageView") as? PasscodeManageViewController else { return }
passcodeManageView.state = State.loginMode
passcodeManageView.modalPresentationStyle = .overFullScreen
var rootViewController = UIApplication.shared.keyWindow?.rootViewController
while let presentController = rootViewController?.presentedViewController {
rootViewController = presentController
}
rootViewController?.present(passcodeManageView, animated: false, completion: nil)
}
但是,如何在 applicationDidEnterBackground(:_) 中关闭 launchScreen?
我怎样才能找到特定的视图控制器并关闭它?
根据Apple 文档 applicationDidEnterBackground(_:)` https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622997-applicationdidenterbackground
使用此方法可以释放共享资源,使计时器无效,并存储足够的应用程序状态信息,以便将应用程序恢复到当前状态,以防以后终止。您还应该禁用应用程序用户界面的更新并避免使用某些类型的共享系统资源(例如用户的联系人数据库)。您还必须避免在后台使用 OpenGL ES。
应用程序进入后台后,您不应关闭启动屏幕。但如果您仍然想实现它,请使用window?.rootViewController?
解雇,因为此时,window?.rootViewController?
是启动屏幕
func applicationDidEnterBackground(_ application: UIApplication) {
if (window?.rootViewController?.isKind(of: YOUR_LAUNCH_SCREEN_CLASS.self))! {
window?.rootViewController?.dismiss(animated: true, completion: nil)
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)