不能选择使用带有 LazyVGrid 的完整 2960x1440 壁纸,因为它会导致性能不令人满意,即使在 iPhone 12 Pro 上也是如此。
所有资产都存储在资产目录中。这些是模型:
struct Thumbnail: Identifiable {
var id = UUID()
var name: String
}
struct Wallpaper: Identifiable {
var id = UUID()
var name: String
}
let thumbnailSet = (1...50).map { Thumbnail(name: "thumbnail-\($0)") }
let wallpaperSet = (1...50).map { Wallpaper(name: "wallpaper-\($0)") }
图库是一个简单的两列网格:
import SwiftUI
struct GalleryView: View {
@State private var fullScreen = false
let columns = [
GridItem(.flexible(), spacing: 2),
GridItem(.flexible())]
var body: some View {
ZStack {
// GRID VIEW
ScrollView(showsIndicators: false) {
VStack {
LazyVGrid(columns: columns, spacing: 2) {
ForEach(thumbnailSet.indices) { index in
Image(thumbnailSet[index].name)
.resizable()
.aspectRatio(contentMode: .fit)
.onTapGesture {(fullScreen = true)}
}
}
}
}
.ignoresSafeArea()
// FULL SCREEN VIEW
if fullScreen {
ZStack {
// Code to show corresponding wallpaper?
// BACK TO GRID VIEW
Button(action: {
(fullScreen = false)
}) {Image(systemName: "chevron.left")
.font(.system(size: 23))
.frame(width: 48, height: 44)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
}
.zIndex(1)
}
}
}
}
这是可行的吗?想法?
谢谢!