【发布时间】:2020-06-28 06:05:08
【问题描述】:
我在 SplitView 中有一个 List,并且希望 List 行的高度随 ScrollView 的宽度而缩放。如何在 SwiftUI 列表中执行此操作。
不确定使用GeometryReader 是否正确,但它似乎有效。
struct BrowserView: View {
@ObservedObject var controller = FileController.shared
var body: some View {
GeometryReader {geometry in
List(selection: self.$controller.selectedObject) {
ForEach(self.controller.thumbNails, id:\.self) { object in
AssetThumbnail(object: object
).aspectRatio(contentMode: .fit).frame(idealHeight: geometry.size.width * 2 / 3 )
.tag(object.id)
}
}
}
}
}
【问题讨论】: