LazyHStack和HStack在高度方面的行为不同,原因是什么?(VStack同理)。
import SwiftUI
struct LazyTestView: View {
var body: some View {
LazyHStack {
ForEach(1...10, id: \.self) { int in
Text("\(int)")
}
}
}
}
struct LazyTestView_Previews: PreviewProvider {
static var previews: some View {
LazyTestView()
.previewLayout(.sizeThatFits)
}
}
相反,使用 HStack:
import SwiftUI
struct LazyTestView: View {
var body: some View {
HStack {
ForEach(1...10, id: \.self) { int in
Text("\(int)")
}
}
}
}
一种解决方案是为LazyHStack添加.fixedSize()... PS: Xcode版本12.5 beta (12E5220o)
.fixedSize()
而不是_Sized_。 - erick2red