我大致有:
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 size
消息气泡which is always taller than its
头像视图and
VStack`兄弟姐妹。
问题是当我添加一个Spacer
在 - 的里面VStack
,那么整个HStack
令人难以置信的增长。这Spacer
就是“贪婪”地让万物无限生长。
我确实希望在顶部有一个按钮,在底部有另一个按钮VStack
同时被限制于MessageBubble
的身高。
我怎样才能让它增长不超过MessageBubble
?
如果我理解正确的话你期望这样的东西(元素对齐)
这是演示代码(彩色矩形的框架在这里并不重要,尺寸仅用于演示,您将在那里放置视图):
struct TestAlignmentSize: View {
@State var height: CGFloat = 40
var body: some View {
HStack(alignment: .top, spacing: 20) {
Rectangle()
.fill(Color.blue)
.frame(width: 50, height: 50)
Rectangle()
.fill(Color.red)
.frame(width: 100, height: 200)
.alignmentGuide(.top, computeValue: { d in // [!!]
self.height = d.height
return d[.top]
})
VStack {
Button(action: {}) {
Image(systemName: "chevron.down")
}
Spacer()
Button(action: {}) {
Text("Button")
}
}.frame(height: self.height) // [!!]
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)