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.
| Property | Description |
|---|---|
scale read-only | The distance between the two fingers relative to the start of the gesture |
velocity read-only | How 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
| Object | Events |
|---|---|
UIPinchGestureRecognizer | began, 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
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
| ObjC | JS |
|---|---|
recognizer.scale | event.scale |
recognizer.velocity | event.velocity |
See also
UIPinchGestureRecognizer: the object that fires these eventsUIGestureRecognizerEvent: the parent class