viewDidAppear() 按下主页按钮后再次启动时未被调用



我注意到当按下主屏幕然后再次启动时,没有调用viewDidAppear。这就是为什么我的动画在我按下主页按钮然后再次启动我的应用程序后停止工作的原因。有什么办法可以解决这个问题吗?

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print("View did appear is launched")
tapToPlayLabel.startBlink()
settingsButton.startRotating()
}

首先,在通知中心注册以检测进入前台的应用程序。

NotificationCenter.default.addObserver(self, selector: #selector(appMovedToForeground), name: Notification.Name.UIApplicationWillEnterForeground, object: nil)

然后在处理程序函数中执行所需的任何动画

func appMovedToForeground() {
tapToPlayLabel.startBlink()
settingsButton.startRotating()
}