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