UIGestureRecognizerEvent: location property
The location property is the gesture position, in the coordinate system of the view the recognizer is attached to.
Value
- Read-only. Assigning to it throws
TypeError. - With several fingers, it is their center point.
- To convert it to another view's coordinate system, use
convertPoint()ofUIView. - When the event is created with
newwithout it, it isnull.
Examples
js
const card = new UIView();
const tap = new UITapGestureRecognizer();
tap.addEventListener('ended', (e) => {
if (e.location !== null) {
console.log('点在', e.location.x, e.location.y);
}
});
card.addGestureRecognizer(tap);Effect: tapping card prints 点在 and the position of the tap.
Corresponding iOS API
[recognizer locationInView:recognizer.view].