Skip to content

UIPinchGestureRecognizerEvent ​

UIPinchGestureRecognizerEvent represents an event of a pinch gesture: beginning, changing, ending, or being canceled.

On top of UIGestureRecognizerEvent, it carries the scale and its speed.

Inheritance: Event → UIGestureRecognizerEvent → UIPinchGestureRecognizerEvent

Constructor ​

UIPinchGestureRecognizerEvent()

Creates a UIPinchGestureRecognizerEvent. 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
scale read-onlyThe distance between the two fingers relative to the start of the gesture
velocity read-onlyHow much scale changes per second

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
UIPinchGestureRecognizerbegan, 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 photo = new UIView();
const pinch = new UIPinchGestureRecognizer();
pinch.addEventListener('changed', (e) => {
  console.log(e instanceof UIPinchGestureRecognizerEvent, e.scale.toFixed(2));
});
photo.addGestureRecognizer(pinch);

Effect: while pinching on photo, prints true and the current scale.

Corresponding iOS API ​

ObjCJS
recognizer.scaleevent.scale
recognizer.velocityevent.velocity

See also ​