SwiftUI中可以使用 onTapGesture
和 onLongPressGesture
对单击和长按手势进行监听。而对于双击手势,可以使用 onTapGesture
并设置 numberOfTapsRequired
属性为 2。
以下是一个示例代码:
struct ContentView: View {
var body: some View {
Text("Hello World")
.onTapGesture(count: 2) { // 双击手势
print("Double tapped")
}
.onTapGesture { // 单击手势
print("Single tapped")
}
.onLongPressGesture {
print("Long pressed")
}
}
}