Skip to content

UISwipeGestureRecognizer ​

UISwipeGestureRecognizer represents a swipe recognizer: it recognizes the gesture when a finger moves quickly across the screen in a given direction. By default it recognizes a one-finger swipe to the right. Moving slowly doesn't count as a swipe.

A swipe is a discrete gesture: once recognized, it's over, and ended fires exactly once. The event doesn't say which direction was recognized; to tell directions apart, create one recognizer per direction.

Swiping hasn't been checked with real touches yet. The gesture itself is not verified in the simulator.

Inheritance: EventTarget → NSObject → UIGestureRecognizer → UISwipeGestureRecognizer

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

Constructor ​

UISwipeGestureRecognizer()

Creates a recognizer for one-finger swipes to the right.

Instance properties ​

It also inherits the properties of UIGestureRecognizer; the commonly used ones are isEnabled, view, and cancelsTouchesInView. All of its methods are inherited from it too: addEventListener(), removeEventListener(), and requireGestureRecognizerToFail().

PropertyDescription
numberOfTouchesRequiredHow many fingers must swipe together
directionWhich directions of swipe to recognize

Events ​

The events come from UIGestureRecognizer; listen with addEventListener(). This recognizer fires:

EventWhen it fires
endedWhen the swipe is recognized. A swipe fires only this one event

Examples ​

js
const card = new UIView();
const swipeLeft = new UISwipeGestureRecognizer();
swipeLeft.direction = ['left'];
swipeLeft.addEventListener('ended', () => {
  console.log('Swiped left');
});
card.addGestureRecognizer(swipeLeft);

Effect: When a finger moves quickly to the left across card, it prints Swiped left. Not verified in the simulator.

Corresponding iOS API ​

ObjCJS
swipe.direction = UISwipeGestureRecognizerDirectionLeftswipe.direction = ['left']
swipe.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRightswipe.direction = ['left', 'right']
swipe.numberOfTouchesRequired = 2swipe.numberOfTouchesRequired = 2

See also ​