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
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().
| Property | Description |
|---|---|
rotation | The angle turned since the start of the gesture, in radians |
velocity read-only | The rotation velocity, in radians per second |
Events
Events come from UIGestureRecognizer; listen with addEventListener(). It fires:
| Event | When it fires |
|---|---|
began | When the rotation is recognized |
changed | Each time the angle changes after that |
ended | When the fingers lift |
cancelled | When interrupted |
Examples
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
| ObjC | JS |
|---|---|
rotation.rotation | The event object's rotation, or twist.rotation |
rotation.velocity | The event object's velocity, or twist.velocity |
See also
- Responding to gestures
CGAffineTransformUIGestureRecognizer: the parent class, with the events and shared properties