gpt4 book ai didi

ios - 检测 applicationWillEnterForeground 中存在哪个 View

转载 作者:搜寻专家 更新时间:2023-11-01 06:28:54 24 4
gpt4 key购买 nike

我想知道当应用程序进入前台时出现哪个 View 。

这怎么可能?

func applicationWillEnterForeground(_ application: UIApplication) {

if (storyboardID == "myview") {

//do sth

}

}

最佳答案

func getCurrentViewController() -> UIViewController? {

if let rootController = UIApplication.shared.keyWindow?.rootViewController {
var currentController: UIViewController! = rootController
while (currentController.presentedViewController != nil) {
currentController = currentController.presentedViewController
}
return currentController
}
return nil
}

使用上面的代码你会得到当前的View Controller。

使用示例

func applicationWillEnterForeground(_ application: UIApplication) {
if let storyboardID = getCurrentViewController()?.restorationIdentifier,
storyboardID == "myview") {
//do sth
}
}

关于ios - 检测 applicationWillEnterForeground 中存在哪个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49999572/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com