Recommended way to detect double-tap on UIButton and scope of UIControl.Event

I’m trying to detect a double-tap action on a UIButton. There seem to be two possible approaches:

Using a UITapGestureRecognizer with numberOfTapsRequired = 2.

Using the .touchDownRepeat event of UIControl.Event.

What is the recommended approach for reliably handling double-taps on UIButton? Are there any practical differences in terms of behavior, performance, or best practices between these two methods?

Additionally, I noticed that UIControl.Event defines a large set of events (like .editingChanged, .valueChanged, etc.).

Can all these events be applied to any UIControl subclass such as UIButton, or are they only valid for specific controls like UITextField, UISlider, etc.?

If not all events are supported by all controls, what is the rationale behind exposing them under a shared UIControl.Event enum?

Thanks in advance!

I recommend the simplest (that's what I use): UITapGestureRecognizer with numberOfTapsRequired = 2.

The difference is that it is made specifically for the purpose of doublets. And impossible to detect any performance difference, if ever there were.

If you want to have a different action for single and double tap on theObject, you should create 2 gestures (you could create the gestures in storyboard):

    let doubleTap = UITapGestureRecognizer(target: self, action : #selector(self.doubleTapped(tap:))) 
    doubleTap.numberOfTapsRequired = 2
    self.theObject.addGestureRecognizer(doubleTap)

    let singleTap = UITapGestureRecognizer(target: self, action: #selector(self.singleTapped(tap:)))
    singleTap.numberOfTapsRequired = 1
    self.theObject.addGestureRecognizer(singleTap)

        // For doubleTap to be detected, avoid interception by single tap: singleTap will fire only if doubleTap has timedout.
        singleTap.require(toFail: doubleTap)

And create the appropriate actions:

    @objc func singleTapped(tap: UIGestureRecognizer) {  }
    @objc func doubleTapped(tap: UIGestureRecognizer) { }

I noticed that UIControl.Event defines a large set of events (like .editingChanged, .valueChanged, etc.). Can all these events be applied to any UIControl subclass such as UIButton

No, for instance, editingChanged has no meaning for a button.

This would depend on what you’re trying to achieve and the context, sharing that would help. Touches and taps are semantically different.

That said UITapGestureRecognizer gives you a different level of customizations and flexibility, such as specifying the numberOfTapsRequired and the numberOfTouchesRequired, and allowing you specify a failure requirements.

You can also have custom touch handling and override touchesBegan, touchesMoved,touchesEnded or touchesCancelled for a fine-grained control over user interaction

@DTS Engineer, Is there some preference order in which we should use these ways to handle events? Say I want to handle a simple button click event where the user presses the button in UI using a single touch/tap.

what should I use in this case?

  1. using addTarget() way to handle the .touchUpInside UIControl event.

  2. using UITapGestureRecognizer(with numberOfTapsRequired = 1 & numberOfTouchesRequired = 1)

  3. or using the custom touch handlers overriding touchesBegan, touchesMoved,touchesEnded

Is there some recommendation like If all these options does the work then I should prefer one over the other. Or it does not matter we can use any ?

Recommended way to detect double-tap on UIButton and scope of UIControl.Event
 
 
Q