Skip to content

UIPanGestureRecognizerEvent ​

UIPanGestureRecognizerEvent represents an event of a pan gesture: beginning, moving, ending, or being canceled.

On top of UIGestureRecognizerEvent, it carries how far the finger has moved and how fast.

Inheritance: Event → UIGestureRecognizerEvent → UIPanGestureRecognizerEvent

Constructor ​

UIPanGestureRecognizerEvent()

Creates a UIPanGestureRecognizerEvent. 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 location and numberOfTouches from UIGestureRecognizerEvent, and the properties of Event; the most commonly used are type and target. The properties below are read-only; assigning to them throws TypeError.

PropertyDescription
translation read-onlyHow far the finger has moved since the gesture began
velocity read-onlyHow fast the finger is moving

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
UIPanGestureRecognizer, UIScreenEdgePanGestureRecognizerbegan, changed, ended, cancelled

It can't be canceled: cancelable is false, and preventDefault() has no effect. All the values are the ones at the moment the event happened: the callback runs later than the gesture, so the recognizer no longer has those values.

Examples ​

js
const card = new UIView();
const drag = new UIPanGestureRecognizer();
drag.addEventListener('changed', (e) => {
  console.log(e instanceof UIPanGestureRecognizerEvent, e.translation.x, e.velocity.x);
});
card.addGestureRecognizer(drag);

Effect: while dragging on card, each move prints true, the horizontal distance, and the horizontal speed.

Corresponding iOS API ​

ObjCJS
[recognizer translationInView:recognizer.view]event.translation
[recognizer velocityInView:recognizer.view]event.velocity

See also ​