Listening to UITouch event along with UIGestureRecognizer

前端 未结 2 1863
慢半拍i
慢半拍i 2021-01-02 19:07

I am creating a custom UIView and adding a UITapGestureRecognizer on it. I have a handler for the tap gesture. But at the same time I want my UIView to listen to touchesBega

相关标签:
2条回答
  • 2021-01-02 19:21

    You need to set cancelsTouchesInView (and likely delaysTouchesBegan and delaysTouchesEnded) to NO for the gesture recognizer. The default behavior of a gesture recognizer is to avoid having both it and the view process the touch. These settings let you fine-tune that behavior.

    0 讨论(0)
  • 2021-01-02 19:27

    As stated earlier, you need to set the cancelTouchesInView property to NO on your UITapGestureRecognizer.

    From the Apple Docs:

    cancelsTouchesInView—If a gesture recognizer recognizes its gesture, it unbinds the remaining touches of that gesture from their view (so the window won’t deliver them). The window cancels the previously delivered touches with a (touchesCancelled:withEvent:) message. If a gesture recognizer doesn’t recognize its gesture, the view receives all touches in the multi-touch sequence.

    Further reading: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIGestureRecognizer_Class/

    0 讨论(0)
提交回复
热议问题