UIControlTouchEvent
UIControlTouchEvent represents a touch event on a control: a finger going down, moving, lifting, or being interrupted.
The nine events whose names start with touch on UIControl and its subclasses (buttons, switches, sliders, and so on) are this class. It carries the finger position and the tap count.
Inheritance: Event → UIControlTouchEvent
Constructor
Creates a UIControlTouchEvent. The runtime creates one itself when it fires the events below; app code can use it to build an event object and fire it with dispatchEvent() to try out a listener.
Instance properties
Also inherits the properties of Event; the most commonly used are type and target. The properties below are read-only; assigning to them throws TypeError.
| Property | Description |
|---|---|
location read-only | The finger position, in the control's own coordinate system |
tapCount read-only | The tap count |
These properties live on the prototype, not on the event object itself: Object.keys(event) and { ...event } don't include them, so read them one by one. See Events with fields.
Events that use this class
| Object | Events |
|---|---|
UIControl and its subclasses | touchdown, touchdownrepeat, touchdraginside, touchdragoutside, touchdragenter, touchdragexit, touchupinside, touchupoutside, touchcancel |
It can't be canceled: cancelable is false, and preventDefault() has no effect.
Examples
const card = new UIControl();
card.addEventListener('touchupinside', (e) => {
console.log(e instanceof UIControlTouchEvent, e.location?.x, e.tapCount);
});
card.sendActionsForControlEvents(['touchupinside']);Effect: prints true undefined 0: an event fired from code has no real touch, so location is null. When a finger lifts on card, it prints true, the finger's x, and the tap count.
Corresponding iOS API
A native action method receives a UIEvent and reads the position and tap count from its UITouch. Here both are directly on the event object.
| ObjC | JS |
|---|---|
[touch locationInView:control] | event.location |
touch.tapCount | event.tapCount |
See also
UIControl: the object that fires these events- Handling touches on controls: the order of the nine events