我做了一些代码,当用户在屏幕上的任何地方点击时,点/分数/点击将增加 1。但问题是它会计算我连续点击的次数,然后如果我在两者之间留下 1 秒的间隔按下它将重新启动计数器。有什么办法可以让它停止重新启动?
代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var tapsLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
let tapCount = touch.tapCount
tapsLabel.text = "Taps: \(tapCount)"
}
}