How to differentiate between user swipe and tap action?

后端 未结 2 1928
面向向阳花
面向向阳花 2021-01-21 16:55

I am developing a app in which I have a view which contains subView in it. I want to track both swipe and tap actions such as a single click.

Actions should be tracked

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

    The best place to get the information is Defining How Gesture Recognizers Interact of Event Handling Guide for iOS

    When a view has multiple gesture recognizers attached to it, you may want to alter how the competing gesture recognizers receive and analyze touch events. By default, there is no set order for which gesture recognizers receive a touch first, and for this reason touches can be passed to gesture recognizers in a different order each time. You can override this default behavior to:

    • Specify that one gesture recognizer should analyze a touch before another gesture recognizer.
    • Allow two gesture recognizers to operate simultaneously.
    • Prevent a gesture recognizer from analyzing a touch.
    0 讨论(0)
  • 2021-01-21 17:30

    You can use UITapGestureRecognizer for tap gestures.

    "UITapGestureRecognizer is a concrete subclass of UIGestureRecognizer that looks for single or multiple taps. For the gesture to be recognized, the specified number of fingers must tap the view a specified number of times."

    This method includes the numberOfTapsRequired ("The number of taps for the gesture to be recognized.") and numberOfTouchesRequired ("The number of fingers required to tap for the gesture to be recognized") properties where you can set exactly how you want it to react to user action.

    In this case, as you only want it to be activated when tapped once, the default settings for both these properties (both have default values of 1) should be fine.

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