3.12_如何读取tap和double Tap手势

1. 简介

我们可以给任何 SwiftUI 视图附加 点击操作(tap action),并且可以指定在触发操作之前应该接收的点击次数。

2. 示例

例如: 我们创建一个文本视图,在点击时将打印消息:

struct ContentView: View {
    var body: some View {
        Text("Tap me!")
            .onTapGesture {
                print("Tapped!")
            }
    }
}

效果预览: 3.12_tap_gesture_tap_a_text

再创建一个图像视图,当双击时将打印消息:

struct ContentView : View {
    var body: some View {
        Image("example-image")
            .onTapGesture(count: 2) {
                print("Double tapped!")
            }
    }

效果预览: 3.12_tap_gesture_double_tap_a_image

Avatar
M X
Mobile, Front-End Developer

My research interests include swift developing, python developing and go developing.

Related

Next
Previous
comments powered by Disqus