---
title: "gesture(_:isEnabled:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/gesture(_:isenabled:)"
---

# gesture(_:isEnabled:)

Attaches a gesture to the view with a lower precedence than gestures defined by the view.

## Declaration

```swift
nonisolated func gesture<T>(_ gesture: T, isEnabled: Bool) -> some View where T : Gesture

```

## Parameters

- `gesture`: A gesture to attach to the view.
- `isEnabled`: Whether the added gesture is enabled.

## Discussion

Discussion Use this method when you need to attach a gesture to a view. The example below defines a custom gesture that prints a message to the console and attaches it to the view’s VStack. Inside the VStack a red heart Image defines its own TapGesture handler that also prints a message to the console, and blue rectangle with no custom gesture handlers. Tapping or clicking the image prints a message to the console from the tap gesture handler on the image, while tapping or clicking  the rectangle inside the VStack prints a message in the console from the enclosing vertical stack gesture handler. You can also use the isEnabled parameter to conditionally disable the gesture. struct GestureExample: View {     @State private var message = "Message"     var isGestureEnabled: Bool     let newGesture = TapGesture().onEnded {         print("Tap on VStack.")     }

var body: some View {         VStack(spacing:25) {             Image(systemName: "heart.fill")                 .resizable()                 .frame(width: 75, height: 75)                 .padding()                 .foregroundColor(.red)                 .onTapGesture {                     print("Tap on image.")                 }             Rectangle()                 .fill(Color.blue)         }         .gesture(newGesture, isEnabled: isGestureEnabled)         .frame(width: 200, height: 200)         .border(Color.purple)     } }

## See Also

### Recognizing gestures that change over time

- [gesture(_:)](swiftui/view/gesture(_:).md)
- [gesture(_:name:isEnabled:)](swiftui/view/gesture(_:name:isenabled:).md)
- [gesture(_:including:)](swiftui/view/gesture(_:including:).md)
- [DragGesture](swiftui/draggesture.md)
- [WindowDragGesture](swiftui/windowdraggesture.md)
- [MagnifyGesture](swiftui/magnifygesture.md)
- [RotateGesture](swiftui/rotategesture.md)
- [RotateGesture3D](swiftui/rotategesture3d.md)
- [GestureMask](swiftui/gesturemask.md)
