UIPanGestureRecognizerEvent: velocity property
The velocity property is how fast the finger is moving when this event happens.
Value
A CGPoint in the coordinate system of the recognizer's view, in pt per second. The signs of x and y follow translation.
- Read-only. Assigning to it throws
TypeError. - In
ended, it is the speed at the moment the finger lifted; use it to tell whether the user flicked. - When the event is created with
newwithout it, it isnull.
Examples
js
const card = new UIView();
const drag = new UIPanGestureRecognizer();
drag.addEventListener('ended', (e) => {
if (e.velocity.x > 1000) {
console.log('向右甩出');
}
});
card.addGestureRecognizer(drag);Effect: swiping right quickly on card and lifting the finger prints 向右甩出.
Corresponding iOS API
[recognizer velocityInView:recognizer.view].