我ViewController.swift暂停计时器时应用程序是在后台状态斯威夫特
func startTimer() {
timer = NSTimer().scheduleTimerWithTimerInvterval(1.0,target: self,selctor: Selector("couting"),userinfo: nil, repeats: true)
}
func pauseTimer() {
timer.invalidate()
println("pausing timer")
}
,这是appDelegate.swift
func applicateWillResignActive(application: UIApplication) {
viewController().pauseTimer()
println("closing app")
}
正在打印暂停定时器和关闭应用程序但是当我打开我再次看到它永不停歇。我如何正确地做到这一点?
试试这个控制,希望这会对你有帮助。 https://www.cocoacontrols.com/controls/game-timer –
,当应用程序处于后台状态时不会暂停 – user528432