The number of taps or clicks required to trigger the action closure provided in action
. Defaults to 1
.
Instance Method
インスタンスメソッド
on
onTapGesture(count:perform:)
Adds an action to perform when this view recognizes a tap gesture.
このビューがタップジェスチャを認識する時に実行するアクションを加えます。
Availability 有効性
- iOS 13.0+
- iPadOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- watchOS 6.0+
Technology
- Swift
UI
Declaration 宣言
Parameters パラメータ
count
action
The action to perform. 実行するアクション。
Discussion 議論
Use this method to perform a specific action
when the user clicks or taps on the view or container count
times.
Note 注意
If you are creating a control that’s functionally equivalent to a Button
, use Button
to create a customized button instead.
In the example below, the color of the heart images changes to a random color from the colors
array whenever the user clicks or taps on the view twice:
struct TapGestureExample: View {
let colors: [Color] = [.gray, .red, .orange, .yellow,
.green, .blue, .purple, .pink]
private var fgColor: Color = .gray
var body: some View {
Image(systemName: "heart.fill")
.resizable()
.frame(width: 200, height: 200)
.foregroundColor(fgColor)
.onTapGesture(count: 2) {
fgColor = colors.randomElement()!
}
}
}