SwiftUI:添加 .frame maxHeight 后,列表中的图像不再居中
SwiftUI: Images in a List are no longer center after adding a .frame maxHeight
我正在显示 List
图像,效果很好。它们都在列表中居中,但是当我添加 maxHeight
时,图像移动到前导而不是居中,所以我将对齐方式设置为 .center
,但这似乎没有任何作用。
NavigationView {
List(words, id: \.self) { word in
NavigationLink(destination: testView(word: word)) {
Image(word.imageName)
.resizable()
.aspectRatio(contentMode: .fit)
.frame( maxHeight: 200, alignment: .center )
}
}
}
有其他人遇到过这个问题并且知道如何解决吗?
谢谢
这是我从 Apple 收到的反馈:
Engineering has provided the following information regarding this
issue:
You need the frame to have an infinite width. This is a layout bug.
Please try using a frame with infinite width.
将 maxWidth 设置为 .infinity 确实解决了该错误。
例如:
.frame(maxWidth: .infinity, maxHeight: 250)
我正在显示 List
图像,效果很好。它们都在列表中居中,但是当我添加 maxHeight
时,图像移动到前导而不是居中,所以我将对齐方式设置为 .center
,但这似乎没有任何作用。
NavigationView {
List(words, id: \.self) { word in
NavigationLink(destination: testView(word: word)) {
Image(word.imageName)
.resizable()
.aspectRatio(contentMode: .fit)
.frame( maxHeight: 200, alignment: .center )
}
}
}
有其他人遇到过这个问题并且知道如何解决吗?
谢谢
这是我从 Apple 收到的反馈:
Engineering has provided the following information regarding this issue:
You need the frame to have an infinite width. This is a layout bug. Please try using a frame with infinite width.
将 maxWidth 设置为 .infinity 确实解决了该错误。
例如:
.frame(maxWidth: .infinity, maxHeight: 250)