swift 如何计算屏幕被触摸的次数?

How to Count the number of times the screen be touched in swift?

如何获取屏幕被触摸的次数 swift 我不会

知道用什么方法的请帮忙

很简单,在最上面声明一个计数器即可,var counter = 0

然后使用函数,输入touchesBegan就会显示

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    counter++
    print(counter)
}

创建静态变量计数器 = 0
计数器应该是静态变量。

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
counter++
print(counter)
}