[英]Catch Tap gesture on Form in SwiftUI
struct ContentView: View {
@State var text = ""
var body: some View {
Form {
Button(action: {
print("Button pressed")
}) {
Text("Button")
}
}.simultaneousGesture(TapGesture().onEnded( { print("tap") }))
}
}
I need both Button' action and tap gesture on Form
to be caught, but only print("tap")
is executed.我需要捕捉
Form
上的按钮动作和点击手势,但只执行print("tap")
。 For a VStack
works fine, but it seems the Form
is a little bit special.对于
VStack
工作正常,但似乎Form
有点特别。 Any idea?任何想法?
if you do it like this, you will get the button tap (but also the form tap).如果您这样做,您将获得按钮点击(还有表单点击)。 I don't know if this helps you.
我不知道这是否对你有帮助。
@State var text = ""
var body: some View {
Form {
Button(action: {
}) {
Text("Button")
}.onTapGesture {
print("button")
}
}.onTapGesture {
print("form")
} }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.