One Logo Pool Ball
SwiftUI · IOS API REFERENCE

UIGestureRecognizerRepresentable

protocol · iOS 18.0+ · SDK 27.1

@MainActor @preconcurrency protocol UIGestureRecognizerRepresentable

A wrapper for a `UIGestureRecognizer` that you use to integrate that gesture recognizer into your SwiftUI hierarchy. Use a ``UIGestureRecognizerRepresentable`` instance to create and manage a <doc://com.apple.documentation/documentation/UIKit/UIGestureRecognizer> object in your SwiftUI interface. To add your gesture recognizer to a SwiftUI view, create an instance of ``UIGestureRecognizerRepresentable`` and use the ``View/gesture(_:)`` modifier to attach it. The system calls the methods of your representable instance at appropriate times to create and update the gesture recognizer. The following example shows the inclusion of a custom `MyGestureRecognizer` structure in the view hierarchy. struct ContentView: View { var body: some View { VStack { Image("Mountain").gesture(MyGestureRecognizer()) } } } Because your ``UIGestureRecognizerRepresentable`` is a struct, it can use the environment, have data dependencies, and is more similar to views in SwiftUI. The system will call the appropriate methods on your instance to propagate the latest data. ## Handling Gesture Recognizer Actions SwiftUI automatically installs a target to handle the gesture recognizer's action on your behalf. Implement the `handleUIGestureRecognizerAction` method to react to the gesture recognizing its action. You can optionally include a coordinator object to forward delegate messages from your gesture recognizer or add additional targets. ## Coordinate Space Conversions The gesture recognizer you create may not be attached to a `UIView` in the hierarchy, or it may return a view with different geometry than your SwiftUI view. To handle this, use the converter on the context to perform coordinate space conversions from the global coordinate space. You can pass the gesture recognizer and a SwiftUI coordinate space to the converter to retrieve a final converted point. Passing the ``CoordinateSpaceProtocol/local`` coordinate space (the default) will provide the point in the SwiftUI view the gesture recognizer is attached to.

Members (1)

method · iOS 18.0+

makeCoordinator

Swift declaration
@MainActor @preconcurrency func makeCoordinator(converter: Self.CoordinateSpaceConverter)

Skipped declarations

2 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

UIGestureRecognizerRepresentable.updateUIGestureRecognizer(_:context:)

The iOS SDK compiler rejected this binding: cannot access associated type 'UIGestureRecognizerType' from 'UIGestureRecognizerRepresentable'; use a concrete type or generic parameter base instead

UIGestureRecognizerRepresentable.handleUIGestureRecognizerAction(_:context:)

The iOS SDK compiler rejected this binding: cannot access associated type 'UIGestureRecognizerType' from 'UIGestureRecognizerRepresentable'; use a concrete type or generic parameter base instead

All SwiftUI types →