Skip to content

UIPinchGestureRecognizer() constructor ​

The UIPinchGestureRecognizer() constructor creates a pinch gesture recognizer, which recognizes two fingers spreading apart or pinching together.

Syntax ​

new UIPinchGestureRecognizer()

Parameters ​

None.

Return value ​

A new UIPinchGestureRecognizer. scale is 1, velocity is 0, and it is not attached to any view.

Exceptions ​

TypeError

Subclassing with class X extends UIPinchGestureRecognizer {} and then calling new X() throws TypeError. No native class can be subclassed; see Native classes.

Examples ​

js
const card = new UIView();
const pinch = new UIPinchGestureRecognizer();
pinch.addEventListener('changed', (e) => {
  const { scale } = /** @type {UIPinchGestureRecognizerEvent} */ (e);
  console.log(scale);
});
card.addGestureRecognizer(pinch);

Effect: spreading two fingers on card logs numbers greater than 1; pinching logs numbers less than 1. Not verified in the simulator.

Corresponding iOS API ​

[[UIPinchGestureRecognizer alloc] init]. Natively, initWithTarget:action: registers the callback at the same time; here you create the recognizer first, then listen with addEventListener().

See also ​