按按钮减少的计时器

Timer that reduces by a button

我正在制作一个具有计时器功能的应用程序。我想制作一个从 50 秒开始减少的计时器,但是当您按下按钮时,计时器再次重新启动,但从 49 秒开始。

例如,如果我点击按钮 10 次,计时器会在 40 秒后重新启动。

我该如何解决这个问题?

这是我的代码:

@IBOutlet weak var Counterlabel: UILabel!
var Nbr2 = 51
var timer2 = NSTimer()


override func viewDidLoad() {
    super.viewDidLoad()
    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Counter"), userInfo: nil, repeats: true)
}

@IBAction func Btn1(sender: AnyObject) {

    Nbr = 51

func Counter(){
    Nbr -= 1

    Counterlabel.text = "\(Nbr)"   
}

答案应该是:

class ViewController: UIViewController {

    @IBOutlet weak var Counterlabel: UILabel!
    var Nbr = 51
    var timerValue = 52
    var timer2 = NSTimer()


    override func viewDidLoad() {
        super.viewDidLoad()
        let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Counter"), userInfo: nil, repeats: true)
    }

    @IBAction func Btn1(sender: AnyObject) {

        Nbr = timerValue - 1
        timerValue = timerValue - 1;
    }
    func Counter(){
        Nbr -= 1

        Counterlabel.text = "\(Nbr)"
    }
}