Skip to content

UIRotationGestureRecognizerEvent ​

UIRotationGestureRecognizerEvent represents an event of a rotation gesture: beginning, changing, ending, or being canceled.

On top of UIGestureRecognizerEvent, it carries the angle turned and the rotation speed.

Inheritance: Event → UIGestureRecognizerEvent → UIRotationGestureRecognizerEvent

Constructor ​

UIRotationGestureRecognizerEvent()

Creates a UIRotationGestureRecognizerEvent. 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
rotation read-onlyThe angle turned since the gesture began
velocity read-onlyThe rotation speed

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
UIRotationGestureRecognizerbegan, 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 dial = new UIView();
const turn = new UIRotationGestureRecognizer();
turn.addEventListener('changed', (e) => {
  console.log(e instanceof UIRotationGestureRecognizerEvent, (e.rotation * 180 / Math.PI).toFixed(0));
});
dial.addGestureRecognizer(turn);

Effect: while turning on dial, prints true and the number of degrees turned.

Corresponding iOS API ​

ObjCJS
recognizer.rotationevent.rotation
recognizer.velocityevent.velocity

See also ​