【问题标题】:How to Count the number of times the screen be touched in swift?如何计算快速触摸屏幕的次数?
【发布时间】:2016-03-03 08:35:44
【问题描述】:

如何快速获取屏幕被触摸的次数我没有

知道用什么方法,请帮忙

【问题讨论】:

标签: ios swift swift2 screen uitouch


【解决方案1】:

很简单,在顶部声明一个计数器,var counter = 0

然后使用该功能,只需输入touchesBegan它就会显示

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

【讨论】:

  • 感谢@Lee,您的回答对我帮助很大,但我有一个问题,是否有任何方法可以通过滑动手势制作计数器。我的意思是在滑动动作函数内部而不是在 touchesBegan 函数内部。再次感谢:)
  • @AhmedAssemMostafa 滑动操作是什么意思?
  • 对于这个方法不会调用的按钮操作,如何获取?
  • @AnilkumariOSdeveloper 这不是按钮操作,这是触摸/点击事件
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多