<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/SpatialTapGesture",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI17SpatialTapGestureV"
  },
  "title" : "SpatialTapGesture"
}
-->

# SpatialTapGesture

A gesture that recognizes one or more taps and reports their location.

```
nonisolated struct SpatialTapGesture
```

## Overview

To recognize a tap gesture on a view, create and configure the gesture, and
then add it to the view using the [`gesture(_:including:)`](/documentation/SwiftUI/View/gesture(_:including:)) modifier.
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 TapGestureView: View {
    @State private var location: CGPoint = .zero

    var tap: some Gesture {
        SpatialTapGesture()
            .onEnded { event in
                self.location = event.location
             }
    }

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

## Topics

### Creating a spatial tap gesture

[`init(count:coordinateSpace:)`](/documentation/SwiftUI/SpatialTapGesture/init(count:coordinateSpace:)-75s7q)

Creates a tap gesture with the number of required taps and the
coordinate space of the gesture’s location.

[`init(count:coordinateSpace:)`](/documentation/SwiftUI/SpatialTapGesture/init(count:coordinateSpace:))

Creates a tap gesture with the number of required taps and the
coordinate space of the gesture’s location.

[`init(count:coordinateSpace3D:)`](/documentation/SwiftUI/SpatialTapGesture/init(count:coordinateSpace3D:))

Creates a tap gesture with the number of required taps and the
coordinate space of the gesture’s location.

[`init(count:coordinateSpace:inputKinds:)`](/documentation/SwiftUI/SpatialTapGesture/init(count:coordinateSpace:inputKinds:))

Creates a tap gesture with the number of required taps, the coordinate
space of the gesture’s location, and the input kinds the gesture
recognizes.

[`coordinateSpace`](/documentation/SwiftUI/SpatialTapGesture/coordinateSpace)

The coordinate space in which to receive location values.

[`count`](/documentation/SwiftUI/SpatialTapGesture/count)

The required number of tap events.

### Getting the gesture’s value

[`SpatialTapGesture.Value`](/documentation/SwiftUI/SpatialTapGesture/Value)

The attributes of a tap gesture.

### Deprecated initializers

[`init(count:coordinateSpace:)`](/documentation/SwiftUI/SpatialTapGesture/init(count:coordinateSpace:)-1b85g)

Creates a tap gesture with the number of required taps and the
coordinate space of the gesture’s 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)