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

viewDidAppear() not being called when home button is pressed then launched again

我注意到当按下主屏幕然后再次启动时,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()
}