【发布时间】:2020-03-15 10:03:03
【问题描述】:
我大概有:
var body: some View
{
HStack(alignment: .top) {
AvatarView()
MessageBubble()
if message.isDeleted != true
{
VStack {
Button(action: {
// ...
}) {
Image(systemName: "chevron.down")
}
Spacer() // THIS SPACER
Button(action: {
// ...
}) {
Text("????")
}
}
}
}
}
根HStack~'s height is dictated by the sizeMessageBubblewhich is always taller than itsAvatarViewandVStack` 的兄弟姐妹。
问题是当我在VStack 中添加一个Spacer 时,整个HStack 会难以置信地增长。 Spacer 正在“贪婪”地让一切无限制地增长。
我确实希望在VStack 的最顶部和最底部有一个按钮,同时限制为MessageBubble 的高度。
我怎样才能让它增长不超过MessageBubble?
【问题讨论】:
-
这是一个 Spacer 功能 - 消耗所有可用空间。将其想象成一个将元素向上移动到边缘的弹簧。只是不要使用它,一切都会被它的内容所束缚。
-
刚刚更新了@Asperi的问题。
-
Spacer().frame(minHeight: maxHeight) hackingwithswift.com/quick-start/swiftui/…