gpt4 book ai didi

ios - 当 View 在 ScrollView 内时 onTapGesture 不工作?

转载 作者:行者123 更新时间:2023-12-04 17:26:48 25 4
gpt4 key购买 nike

我有简单的看法。

var body: some View {
NavigationView {
ZStack {
ScrollView {
GeometryReader { geometry in
CardView(geometry: geometry)
.onTapGesture {
print("Tapped")
}
}
.padding()
}
}
}

当我轻敲卡片时,没有打印任何东西。但是,例如,如果我将 scrollView 更改为 VStack,我会立即在控制台上看到 Tapped。怎么了?如何在 scrollView 内的卡片上实现点击手势?

最佳答案

您的问题可能出在 GeometryReader 上,请尝试将其移动到 scrollView 上方而不是内部

var body: some View {
NavigationView {
ZStack {
Color("light_blue_grey")
.edgesIgnoringSafeArea(.all)
GeometryReader { geometry in
ScrollView {
Rectangle()
.foregroundColor(.blue)
.frame(width: geometry.size.width, height: 100)
.onTapGesture {
print("Tapped!")
}

}
.padding()
}
}
}
}

关于ios - 当 View 在 ScrollView 内时 onTapGesture 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62678524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com