<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/onTapGesture(count:coordinateSpace:perform:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE12onTapGesture5count15coordinateSpace7performQrSi_qd__ySo7CGPointVctAA010CoordinateI8ProtocolRd__lF::OverloadGroup"
  },
  "title" : "onTapGesture(count:coordinateSpace:perform:)"
}
-->

# onTapGesture(count:coordinateSpace:perform:)

Adds an action to perform when this view recognizes a tap gesture,
and provides the action with the location of the interaction.

```
nonisolated func onTapGesture(count: Int = 1, coordinateSpace: some CoordinateSpaceProtocol = .local, perform action: @escaping (CGPoint) -> Void) -> some View
```

## Parameters

`count`

The number of taps or clicks required to trigger the action
closure provided in `action`. Defaults to `1`.

`coordinateSpace`

The coordinate space in which to receive
location values. Defaults to [`CoordinateSpace.local`](/documentation/SwiftUI/CoordinateSpace/local).

`action`

The action to perform. This closure receives an input
that indicates where the interaction occurred.

## Discussion

Use this method to perform the specified `action` when the user clicks
or taps on the modified view `count` times. The action closure receives
the location of the interaction.

> Note: If you create a control that’s functionally equivalent
> to a ``doc://com.apple.SwiftUI/documentation/SwiftUI/Button``, use ``doc://com.apple.SwiftUI/documentation/SwiftUI/ButtonStyle`` to create a customized button
> instead.

The following code adds a tap gesture to a [`Circle`](/documentation/SwiftUI/Circle) that toggles the color
of the circle based on the tap location.

```
struct TapGestureExample: View {
    @State private var location: CGPoint = .zero

    var body: some View {
        Circle()
            .fill(self.location.y > 50 ? Color.blue : Color.red)
            .frame(width: 100, height: 100, alignment: .center)
            .onTapGesture { location in
                self.location = location
            }
    }
}
```

---

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)