0
我有一个秒表,我需要禁用停止按钮,直到经过的时间或更长时间,我有它的工作,但如果我要点击停止按钮,在经过的时间发生),然后点击它时间已经过去,它不起作用。如果我启动定时器,并等待或让它通过,如果>10秒它工作正常启用/禁用Xcode 8中的按钮
@IBAction func firstHalfClicked(_ sender: UIButton) {
if startStopWatch == true {
timer = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(StopWatchVC.updateStopwatch), userInfo: nil, repeats: true)
startStopWatch = false
self.firstHalf.alpha = 0.2
self.secondHalf.alpha = 0.2
self.endFirstHalf.alpha = 0.2
self.endSecondHalf.alpha = 0.2
seconds = 0
minutes = 0
tempTimelineLbl.text = "Kick Off here at "
}
}
@IBAction func endFirstHalfClicked(_ sender: UIButton) {
if seconds < 10 {
endFirstHalf.isEnabled = false
} else {
if startStopWatch == false && seconds > 10 {
endFirstHalf.isEnabled = true
timer.invalidate()
startStopWatch = true
seconds = 0
minutes = 45
stopwatchLabel.text = "45:00"
tempTimelineLbl.text = "Half Time"
self.secondHalf.alpha = 1
self.firstHalf.alpha = 0.2
self.endFirstHalf.alpha = 0.2
}
}
}
完美感 – Chet