Skip to content

UIRotationGestureRecognizer ​

UIRotationGestureRecognizer represents a rotation recognizer: it recognizes the gesture when two fingers turn around each other. Use it for two-finger rotation.

Rotation is a continuous gesture and fires began, changed, ended, and cancelled. The event object carries the angle turned since the start of the gesture, rotation (radians), and the rotation velocity velocity. Each gesture's rotation starts from 0.

Rotation has not yet been checked with real touches; the gesture itself and the data carried by its events are not verified in the simulator.

Inheritance: EventTarget → NSObject → UIGestureRecognizer → UIRotationGestureRecognizer

For how to use it, see the guide Responding to gestures.

Constructor ​

UIRotationGestureRecognizer()

Creates a recognizer that recognizes two-finger rotation.

Instance properties ​

Also inherits properties from UIGestureRecognizer; commonly used ones are isEnabled, view, and cancelsTouchesInView. Its methods are all inherited from it too: addEventListener(), removeEventListener(), requireGestureRecognizerToFail().

PropertyDescription
rotationThe angle turned since the start of the gesture, in radians
velocity read-onlyThe rotation velocity, in radians per second

Events ​

Events come from UIGestureRecognizer; listen with addEventListener(). It fires:

EventWhen it fires
beganWhen the rotation is recognized
changedEach time the angle changes after that
endedWhen the fingers lift
cancelledWhen interrupted

Examples ​

js
const card = new UIView();
const twist = new UIRotationGestureRecognizer();
let baseAngle = 0;
twist.addEventListener('changed', (e) => {
  const { rotation } = /** @type {UIRotationGestureRecognizerEvent} */ (e);
  card.transform = CGAffineTransform.rotation(baseAngle + rotation);
});
twist.addEventListener('ended', (e) => {
  const { rotation } = /** @type {UIRotationGestureRecognizerEvent} */ (e);
  baseAngle = baseAngle + rotation;
});
card.addGestureRecognizer(twist);

Effect: When two fingers turn on card, card rotates along with them and keeps its angle after release. Not verified in the simulator.

Corresponding iOS API ​

ObjCJS
rotation.rotationThe event object's rotation, or twist.rotation
rotation.velocityThe event object's velocity, or twist.velocity

See also ​