A gesture that recognizes one or more taps.
To recognize a tap gesture on a view, create and configure the gesture, and
then add it to the view using the ``View/gesture(_:including:)`` modifier.
The following code adds a tap gesture to a ``Circle`` that toggles the color
of the circle:
struct TapGestureView: View {
@State private var tapped = false
var tap: some Gesture {
TapGesture(count: 1)
.onEnded { _ in self.tapped = !self.tapped }
}
var body: some View {
Circle()
.fill(self.tapped ? Color.blue : Color.red)
.frame(width: 100, height: 100, alignment: .center)
.gesture(tap)
}
}
nonisolated init(count: Int = 1, inputKinds: GestureInputKinds = .all)
Creates a tap gesture with the number of required taps and the
input kinds the gesture recognizes.
- Parameters:
- count: The required number of taps to complete the tap
gesture.
- inputKinds: A set of input kinds that this gesture recognizes.
If not specified, the gesture will recognize all applicable input
kinds that a person can use to perform it.
init · iOS 13.0+
init
TypeScript
static initCount(count?: number): TapGesture
Swift declaration
nonisolated init(count: Int = 1)
Creates a tap gesture with the number of required taps.
- Parameter count: The required number of taps to complete the tap
gesture.