我想知道当应用程序进入前台时出现哪个 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/