【发布时间】:2021-02-24 02:00:47
【问题描述】:
我正在为一个应用程序创建一个可重复使用的图库视图,并且在点击任何图片时遇到困难,它假设变成全屏,但无论点击什么图片,每次都只显示数组中的第一张图片。下面是我的代码,谢谢。
导入 SwiftUI
struct ReusableGalleryView: 查看 { 让 greenappData: GreenAppNews
let gridLayout: [GridItem] = Array(repeating: GridItem(.flexible()), count: 3)
@State private var fullscreen = false
@State private var isPresented = false
var body: some View {
VStack{
ScrollView{
LazyVGrid(columns: gridLayout, spacing: 3) {
ForEach(greenappData.GreenAppGallery, id: \.self) { item in
Image(item)
.resizable()
.frame(width: UIScreen.main.bounds.width/3, height: 150)
.onTapGesture {
self.isPresented.toggle()
print(" tapping number")
}
.fullScreenCover(isPresented: $isPresented) {
FullScreenModalView( imageFiller: item)
}
.background(Color.gray.opacity(0.5))
}
}
.padding(.horizontal)
}
}
}
}
这是一个json数据的例子:
{ “id”:“1”, “GreenAppGallery”:[ “图片1”, “图片2”, “图3”, “图4”, “图片5”, “图6”, “图7”, “图8”, “图9”, “图 10” ] },
【问题讨论】:
-
这是否回答了您的问题stackoverflow.com/a/65480211/12299030?
标签: swiftui image-gallery