0
私のコードでは、startButtonのカウントダウンを押すと60〜0になります。 、そのマーク、セットの0だと思い、私たちの前に、うーん0カウントダウンタイマーの前にカウントダウンタイマーを追加する(swift3)
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var startButton: UIButton!
@IBOutlet weak var timerLabel: UILabel!
var seconds = 60
var timer = Timer()
var isTimerRunning = false
var resumeTapped = false
@IBAction func startButtonTapped(_ sender: UIButton) {
if isTimerRunning == false {
runTimer()
self.startButton.isEnabled = false
}
}
func runTimer() {
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: (#selector(ViewController.updateTimer)), userInfo: nil, repeats: true)
isTimerRunning = true
}
@IBAction func resetButtonTapped(_ sender: UIButton) {
timer.invalidate()
seconds = 60
timerLabel.text = timeString(time: TimeInterval(seconds))
isTimerRunning = false
}
//MARK: - Public Method
func updateTimer(){
if seconds < 1 {
timer.invalidate()
//Send alert to indicate time's up.
} else {
seconds -= 1
timerLabel.text = timeString(time: TimeInterval(seconds))
}
}
func timeString(time:TimeInterval) -> String {
let hours = Int(time)/3600
let minutes = Int(time)/60 % 60
let seconds = Int(time) % 60
return String(format:"%02i:%02i:%02i", hours, minutes, seconds)
}}
ここではどのような問題に直面していますか? – KKRocks
私は2つのカウントダウンタイマー3-0と60-0を連鎖しようとしています。 –