gpt4 book ai didi

ios - ScrollView 导航链接在 VStack 和 GeometryReader、XCode12、beta 4 中仍然处于事件状态

转载 作者:行者123 更新时间:2023-12-01 21:27:53 26 4
gpt4 key购买 nike

使用 XCode12,beta 4,我试图将标题区域和 ScrollView 分开。我已经尝试过 VStack 和 GeometryReader;但是,当我单击标题区域时,会触发其下方 ScrollView 项中的导航链接。
如果我使用列表,则不会观察到这种不良行为。如果我在 XCode 11.6 中使用 ScrollView 并为 iOS13 构建,也不会观察到这种不良行为。
VStacks 中的 ScrollViews 或 iOS14 中的 GeometryReaders 有什么变化吗?为什么 ScrollView 在 VStack 或 GeometryReader 中的对象下“滑动”?

struct ContentView: View {
var body: some View {
NavigationView{
//GeometryReader { geo in
VStack{
VStack{
Text("Blah")
}//.frame(height: geo.size.height*0.20)

VStack {
ScrollView {
ForEach(0..<10) { i in
NavigationLink(destination: Text("\(i)")) {
cardRow(i: i)
.frame(maxWidth: .infinity)
.foregroundColor(Color(UIColor.label))
.padding()
.background(RoundedRectangle(cornerRadius: 12))
.foregroundColor(Color(UIColor.secondarySystemFill))
.padding()
}
}
}
}//.frame(height: geo.size.height*0.90)

}
}.navigationViewStyle(StackNavigationViewStyle())
}

struct cardRow: View {
var i: Int

var body: some View {
HStack {
VStack {
Text("88")
}.hidden()
.overlay(
VStack{
Text("\(i)")
}
)
Divider()
.background(Color(UIColor.label))
Spacer()
}
}
}
}

最佳答案

这是有效的解决方案(使用 Xcode 12/iOS 14 测试)

  VStack {
ScrollView {
ForEach(0..<10) { i in
NavigationLink(destination: Text("\(i)")) {
cardRow(i: i)
.frame(maxWidth: .infinity)
.foregroundColor(Color(UIColor.label))
.padding()
.background(RoundedRectangle(cornerRadius: 12))
.foregroundColor(Color(UIColor.secondarySystemFill))
.padding()
}
}
}.clipped().contentShape(Rectangle()) // << here !!
}

关于ios - ScrollView 导航链接在 VStack 和 GeometryReader、XCode12、beta 4 中仍然处于事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63269055/

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