---
title: SpatialTapGesture
framework: swiftui
role: symbol
role_heading: Structure
path: swiftui/spatialtapgesture
---

# SpatialTapGesture

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

## Declaration

```swift
nonisolated struct SpatialTapGesture
```

## Overview

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:) modifier. The following code adds a tap gesture to a 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:)](swiftui/spatialtapgesture/init(count:coordinatespace:)-75s7q.md)
- [init(count:coordinateSpace:)](swiftui/spatialtapgesture/init(count:coordinatespace:).md)
- [init(count:coordinateSpace3D:)](swiftui/spatialtapgesture/init(count:coordinatespace3d:).md)
- [init(count:coordinateSpace:inputKinds:)](swiftui/spatialtapgesture/init(count:coordinatespace:inputkinds:).md)
- [coordinateSpace](swiftui/spatialtapgesture/coordinatespace.md)
- [count](swiftui/spatialtapgesture/count.md)

### Getting the gesture’s value

- [SpatialTapGesture.Value](swiftui/spatialtapgesture/value.md)

### Deprecated initializers

- [init(count:coordinateSpace:)](swiftui/spatialtapgesture/init(count:coordinatespace:)-1b85g.md)

## Relationships

### Conforms To

- [Gesture](swiftui/gesture.md)

## See Also

### Recognizing tap gestures

- [onTapGesture(count:perform:)](swiftui/view/ontapgesture(count:perform:).md)
- [onTapGesture(count:coordinateSpace:perform:)](swiftui/view/ontapgesture(count:coordinatespace:perform:).md)
- [onTapGesture(count:coordinateSpace:inputKinds:perform:)](swiftui/view/ontapgesture(count:coordinatespace:inputkinds:perform:).md)
- [TapGesture](swiftui/tapgesture.md)
