简体   繁体   English

如何设置UIView来检测触摸(不是点击)

[英]How to set up a UIView to detect touches (not taps)

I am trying to make my interface feel more responsive. 我试图使我的界面更具响应性。 A UIView changes color on user touch and I want it to do so already when the View is touched. UIView会在用户触摸时更改颜色,我希望在触摸View时已经更改颜色。 I could implement a UITapGestureRecognizer but a tap is not what I am looking for, since it requires the touch to end before being recognized. 我可以实现UITapGestureRecognizer但是点击不是我想要的,因为它需要触摸结束才能被识别。

I imagine this to be quite simple. 我想这很简单。 Or am I wrong? 还是我错了?

Do I create a custom UIGestureRecognizer class? 是否创建自定义UIGestureRecognizer类?

Have you tried touchedBegan ? 您是否尝试过touchedBegan

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  if let touch = touches.first {
    // ...
  }
  super.touchesBegan(touches, with: event)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM