我注意到当按下主屏幕然后再次启动时,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()
}
关于swift - 按下主页按钮然后再次启动时未调用 viewDidAppear(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45092618/