【发布时间】:2020-09-19 21:42:51
【问题描述】:
当我将 VStack 放入 List 并且 VStack 的其中一个 SubView 是 NavigationLink 时,VStack 的整个区域变为可点击以触发转换,而不仅仅是 SubView。
这是我的问题的一个简化示例:
struct Test: View {
var body: some View {
NavigationView {
List {
VStack { // Entire VStack is tappable.
Rectangle()
.frame(width: 100, height: 200)
.foregroundColor(.red)
NavigationLink(destination: Destination()) {
Rectangle() // I only want this Rectangle to be tappable.
.frame(width: 50, height: 100)
.foregroundColor(.red)
}
}
}
}
}
}
struct Destination: View {
var body: some View {
Text("Hello")
}
}
我已经尝试在任何地方使用BorderlessButtonStyle(),因为它以前可以工作,但由于某种原因它现在不能解决我的问题。
为什么会发生这样的行为?
【问题讨论】:
标签: ios xcode swiftui swiftui-list swiftui-navigationlink