swiftui - 设置可滚动图像 swift UI
问题描述
我试图设置一组图像以获取一些可滚动的图像作为 instagram。
它应该可以使用几何阅读器滚动,但有些东西我不明白。
我尝试设置 2ZStack 并检查显示的位置,然后将视图更新为同一视图。
我的图片在这里
var imagesHaloween: [String] {
var imageNames = [String]()
for i in 1..<8 {
imageNames.append("haloween-\(i)")
}
return imageNames
}
var body: some View {
ZStack {
LinearGradient(gradient: Gradient(colors: [.black, .orange]), startPoint: .topTrailing, endPoint: .bottom)
.ignoresSafeArea(.all)
if !isShown {
ScrollView {
LazyVGrid(columns: columns, spacing: 16) {
ForEach(imagesHaloween, id: \.self) { image in
DetailView(image: image)
.onTapGesture {
withAnimation(.easeIn) {
isShown.toggle()
tempImages.append(contentsOf: imagesHaloween)
tempImages.insert(image, at: 0)
print(tempImages)
}
}
}
}
}
.padding(.top, 50)
.padding()
} else {
ZStack {
ScrollView {
GeometryReader { geo in
VStack {
ForEach(tempImages, id: \.self) { image in
Image(image)
.scaledToFill()
.frame(width: geo.size.width)
.padding()
}
}
}
}
.edgesIgnoringSafeArea(.all)
}
.onTapGesture {
withAnimation(.easeInOut) {
isShown.toggle()
}
}
}
}
}
解决方案
推荐阅读
- algorithm - 为什么使用 for 循环的斐波那契时间复杂度是 O(n^2) 而不是 O(n)?
- python - 尝试使用 python 删除 csv 文件中的额外分隔符时,文本限定符放错了位置
- php - LARAVEL:在单个数组中添加键和值
- linux - 尝试在 bash linux 中使用“新行”命令复制语法
- sql - 如何转换列的值,如 ALL_TAB_COLUMNS 的 HIGH_VALUE 格式
- sql - 多值字段的值仅出现一次的 SQL 选择行
- electron - 将自定义页面/字段添加到使用电子生成器创建的 NSIS 设置
- python - 使用logstash将整个数据库保存到elasticsearch
- rally - 在 Rally 中,使用 Java REST API,如何获取 TestPlan 文件夹的所有子文件夹中存在的测试用例的完整列表?
- reactjs - 在 gitlab 运行器上使用 asar 构建的 React Electron 应用程序会创建 JavaScript 错误