为什么NSTimer.scheduledTimerWithInterval()会在应用程序变为活动状态时恢复?

时间:2016-01-17 17:35:06

标签: ios swift timer swift2 nstimer

在我的应用程序中,我声明了一个计时器:

entropy = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("tick"), userInfo: nil, repeats: true)

熵是:

var entropy: NSTimer

然后,在ApplicationWillResignActive中,熵无效:

main.entropy.invalidate()

主要是:

let main = ViewController()

但是,当应用程序变为活动状态时,计时器将从应用程序重新启动时的最后时间恢复。

我在这里缺少什么?

问候,布兰登

1 个答案:

答案 0 :(得分:0)

这是解决方案:

https://stackoverflow.com/a/27700746/4418557

基本上,我需要将观察者添加到我的ViewController中。有关详细信息,请单击上面的链接。

相关问题