Gestures performed within the bounds of a view can be detected by adding a gesture recognizer to that view. SwiftUI provides detectors for tap, long press, rotation, magnification (pinch) and drag gestures.
A gesture recognizer is added to a view using the gesture() modifier, passing through the gesture recognizer to be added.
In the simplest form, a recognizer will include one or more action callbacks containing the code to be executed when a matching gesture is detected on the view. The following example adds a tap gesture detector to an Image view and implements the onEnded callback containing the code to be performed when the gesture is completed successfully:
struct ContentView: View {
var body: some View {
Image(systemName: "hand.point.right.fill")
.gesture(
...