Swiftui 快捷父母身高
在SwiftUI中,如何将父视图高度设为0并隐藏所有子视图(因为父视图高度为0)。这段代码仍然显示ZStack。它正在从孩子们身上夺走高度Swiftui 快捷父母身高,swiftui,Swiftui,在SwiftUI中,如何将父视图高度设为0并隐藏所有子视图(因为父视图高度为0)。这段代码仍然显示ZStack。它正在从孩子们身上夺走高度 ZStack { RoundedRectangle(cornerRadius: 10.0, style: /*@START_MENU_TOKEN@*/.continuous/*@END_MENU_TOKEN@*/) .fill(Color.red) Image(systemName: "checkma
ZStack {
RoundedRectangle(cornerRadius: 10.0, style: /*@START_MENU_TOKEN@*/.continuous/*@END_MENU_TOKEN@*/)
.fill(Color.red)
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.white)
}
.frame(maxHeight: 0)
.animation(.spring())
您只需要在设置帧后进行剪辑,因为任何堆栈都只是透明的容器,应用的帧实际上是0高度,但内容通过它是可见的,所以解决方案是
ZStack {
RoundedRectangle(cornerRadius: 10.0, style: /*@START_MENU_TOKEN@*/.continuous/*@END_MENU_TOKEN@*/)
.fill(Color.red)
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.white)
}
.frame(maxHeight: 0)
.clipped() // << here !!
.animation(.spring())
ZStack{
圆角转角(拐角半径:10.0,样式:/*@START\u MENU\u TOKEN@*/。continuous/*@END\u MENU\u TOKEN@*/)
.填充(颜色.红色)
图像(系统名称:“选中标记.圆圈.填充”)
.foregroundColor(.白色)
}
.帧(最大高度:0)
.clipped()//