How to differentiate between user swipe and tap action?

后端 未结 2 1931
面向向阳花
面向向阳花 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: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.

提交回复
热议问题