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

标签 swift animation viewdidload

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

相关文章:

ios - TWTRTwitter sessionStore 现在返回 TWTRAuthSession : so how does one access the userName property now?

jQuery 类在输入模糊/事件时淡入淡出

ios - 在 viewDidLoad 方法中链接到另一个 ViewController

ios - viewDidLoad 是否在 UITabBarController 中被多次调用?

swift - Swift 中的 Apple Music 和 AVAudioEngine

swift - 如何更改 UISplitViewController 中的后退按钮?

ios - 你如何在 Swift 中将 NSValue pointerValue() 转换为 UIView?

java - 如何制作一个圆圈的动画

jquery - 使用 ':active' 选择器后如何防止调用我的 css 动画?

iphone - iOS Root View Controller 的 viewDidAppear : called while splash screen (Default. png) 仍然在屏幕上