---
title: "addGestureRecognizer(_:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiview/addgesturerecognizer(_:)"
---

# addGestureRecognizer(_:)

Attaches a gesture recognizer to the view.

## Declaration

```swift
func addGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer)
```

## Parameters

- `gestureRecognizer`: An object whose class descends from the doc://com.apple.uikit/documentation/UIKit/UIGestureRecognizer class. This parameter must not be nil.

## Mentioned in

Handling long-press gestures Handling pan gestures Handling pinch gestures Handling rotation gestures Handling swipe gestures Handling tap gestures

## Discussion

Discussion Attaching a gesture recognizer to a view defines the scope of the represented gesture, causing it to receive touches hit-tested to that view and all of its subviews. The view establishes a strong reference to the gesture recognizer.

## See Also

### Managing gesture recognizers

- [removeGestureRecognizer(_:)](uikit/uiview/removegesturerecognizer(_:).md)
- [gestureRecognizers](uikit/uiview/gesturerecognizers.md)
- [gestureRecognizerShouldBegin(_:)](uikit/uiview/gesturerecognizershouldbegin(_:).md)
