gpt4 book ai didi

ios - 如何在不使用 timer.invalidate() 的情况下重置和暂停计时器

转载 作者:行者123 更新时间:2023-11-28 16:08:36 25 4
gpt4 key购买 nike

<分区>

我希望通过单击 UI 按钮来重置和暂停计时器,但在“重置”计时器时遇到了一些问题。谁能帮忙?开始计时、重置、重新开始时,update func 被多次调用,打乱了倒计时。

@IBAction func startTimer (_ sender: AnyObject) {
var timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: Selector("update"), userInfo: nil, repeats: true)
Reset.isHidden = false
StartButton.isHidden = true
}

@IBAction func resetButton (_ sender: AnyObject) {
Reset.isHidden = true
StartButton.isHidden = false
count = 200
invalidate.t
}



func update() {
if (count > 0) {
let minutes = String(count / 60)
let seconds = String(count % 60)
if (seconds == "0") {
CountDown.text = minutes + ":" + seconds + "0"
} else {
CountDown.text = minutes + ":" + seconds
}
count -= 1
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com