【发布时间】:2021-07-30 13:08:08
【问题描述】:
我正在尝试在 LazyVGrid 中使用 NavigationLink,但我在导航方面遇到了一些麻烦。我希望在单击颜色时可以继续到下一页。这是一些代码:
这是起始页的外观here
以下是图像卡的设置方式:
ZStack{
Color(colorData.image)
.cornerRadius(15)
.aspectRatio(contentMode: .fit)
.padding(8)
.matchedGeometryEffect(id: colorData.image, in: animation)
}
下面是 LazyVgrid 的设置方式:
ScrollView(.vertical, showsIndicators: false, content: {
VStack{
LazyVGrid(columns: Array(repeating: GridItem(.flexible(),spacing: 15), count: 2),spacing: 15){
ForEach(bags){color in
ColorView(colorData: color,animation: animation)
.onTapGesture {
withAnimation(.easeIn){
print("pressed")
selectedColor = color
}
}
}
}
.padding()
.padding(.top,10)
}
})
}
这是我的导航方式:
if selectedColor != nil {
NavigationLink(destination: DetailView()) {}
}
【问题讨论】:
-
你能再显示一些代码吗? selectBag 在哪里定义?您也可以尝试将 ColorView 包装在 NavigationLink 到 DetailView 中。
标签: swiftui swiftui-navigationview