ios - 在 SwiftUI 中的 Form 上捕捉点击手势

标签 ios swift swiftui

struct ContentView: View {

    @State var text = ""
    var body: some View {
        Form {
            Button(action: {
                print("Button pressed")
            }) {
                Text("Button")
            }
        }.simultaneousGesture(TapGesture().onEnded( { print("tap") }))
    }
}

我需要捕获 Form 上的 Button 操作和点击手势,但只执行 print("tap") 。对于 VStack 来说工作正常,但是 Form 似乎有点特殊。有什么想法吗?

最佳答案

如果您这样做,您将获得按钮点击(还有表单点击)。不知道对你有没有帮助。

@State var text = ""
var body: some View {
    Form {
        Button(action: {

        }) {
            Text("Button")
        }.onTapGesture {
            print("button")
        }
    }.onTapGesture {
        print("form")
    }    }
}

关于ios - 在 SwiftUI 中的 Form 上捕捉点击手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58433473/

相关文章:

ios - 无法将我的占位符放在我的 TextView 的右侧

ios - 如何在 iOS 应用程序中使用 'Service account' 实现 Vision API?

ios - 从 SKScene 到 UIViewController 的通信

ios - tableview项目在显示所选项目之前循环遍历所有项目

ios - 如何在 SwiftUI 中查看另一个 View 的大小

objective-c - 所有UI前面的透明UIImageView

ios - 推送通知不适用于 iOS 10

swift - 找不到名为 Type 的枚举

swift - 将数据从 UIKit 传递到 SwiftUI(容器 UIHostingController)

uikit - 从 UIImage 转换为 SwiftUI Image 会产生相同大小的空白图像