Skip to content

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 ​

UIControlTouchEvent()

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.

PropertyDescription
location read-onlyThe finger position, in the control's own coordinate system
tapCount read-onlyThe 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 ​

ObjectEvents
UIControl and its subclassestouchdown, touchdownrepeat, touchdraginside, touchdragoutside, touchdragenter, touchdragexit, touchupinside, touchupoutside, touchcancel

It can't be canceled: cancelable is false, and preventDefault() has no effect.

Examples ​

js
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.

ObjCJS
[touch locationInView:control]event.location
touch.tapCountevent.tapCount

See also ​