<!--
{
  "documentType" : "article",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/handling-swipe-gestures",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Handling swipe gestures"
}
-->

# Handling swipe gestures

Detect a horizontal or vertical swipe motion on the screen, and use it to trigger navigation through your content.

## Discussion

A swipe gesture occurs when a person moves one or more fingers across the screen in a specific horizontal or vertical direction. Use the [`UISwipeGestureRecognizer`](/documentation/UIKit/UISwipeGestureRecognizer) class to detect swipe gestures.

You can attach a gesture recognizer in one of these ways:

- Programmatically. Call the [`addGestureRecognizer(_:)`](/documentation/UIKit/UIView/addGestureRecognizer(_:)) method of your view.
- In Interface Builder. Drag the appropriate object from the library and drop it onto your view.

![A diagram demonstrating a single-finger horizontal swipe gesture.](images/com.apple.uikit/handling-swipe-gestures~dark@2x.png)

A [`UISwipeGestureRecognizer`](/documentation/UIKit/UISwipeGestureRecognizer) object tracks the motion of a person’s finger across the screen either horizontally or vertically. A swipe requires a person’s finger to move in a specific direction and not deviate significantly from the main direction of travel. (The direction and number of fingers required for the gesture are configurable.) Swipe gestures are discrete, so your action method is called only after the gesture ends successfully. As a result, swipes are most appropriate when you care only about the results of the gesture and not about tracking the movement of a person’s finger.

> Note:
> Because swipes are discrete, use them only for flicks or quick panning gestures where the resulting action is understood. Swipes aren’t intended for interactive gestures, such as interactive transitions. For design guidance, see [Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/inputs/touchscreen-gestures/).

The following code shows a skeletal action method for a swipe gesture recognizer. You use a method like this to perform a task when the gesture is recognized. Because the gesture is discrete, the gesture recognizer doesn’t enter the began or changed states.

```swift
@IBAction func swipeHandler(_ gestureRecognizer : UISwipeGestureRecognizer) {
    if gestureRecognizer.state == .ended {
        // Perform action.
    }
}
```

If the code for your swipe gesture recognizer isn’t called, check to see if the following conditions are true, and make corrections as needed:

- The [`isUserInteractionEnabled`](/documentation/UIKit/UIView/isUserInteractionEnabled) property of the view is set to <doc://com.apple.documentation/documentation/Swift/true>. Image views and labels set this property to <doc://com.apple.documentation/documentation/Swift/false> by default.
- The number of touches is equal to the value specified in the [`numberOfTouchesRequired`](/documentation/UIKit/UISwipeGestureRecognizer/numberOfTouchesRequired) property.
- The direction of the swipe matches the value in the [`direction`](/documentation/UIKit/UISwipeGestureRecognizer/direction-swift.property) property.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)