gpt4 book ai didi

ios - swift 用户界面。如何设置 Spacer 的收缩行为?

转载 作者:行者123 更新时间:2023-12-01 19:38:12 25 4
gpt4 key购买 nike

如果容器(VStack)与底部黑色 View (如 iPhone 11 Pro Max)不冲突,如何设置 rgb View (100pt)之间的默认间距。 但是 如果没有 100p 高度的空间,则会缩小。(如屏幕截图上的 iPhone SE)

我的代码:

struct ContentView: View {
var body: some View {
VStack(spacing: 0) {
VStack(spacing: 0) {
Rectangle()
.foregroundColor(.red)
.frame(height: 100)
Spacer()
.frame(minHeight: 10, maxHeight: 100)
Rectangle()
.foregroundColor(.green)
.frame(height: 100)
Spacer()
.frame(minHeight: 10, maxHeight: 100)
Rectangle()
.foregroundColor(.blue)
.frame(height: 100)
}
Spacer()
.frame(minHeight: 10, maxHeight: 600)
Rectangle() // keyboard
.frame(height: 200)
}
}
}

所以问题是:
maxHeight: 100 的垫片在 iPhone 11 Pro Max 上的高度 = 10(不是 100)。 ( 黑色 View 和 VStack 之间的空间允许它)

如何做出我解释的行为?

enter image description here

enter image description here

最佳答案

您需要使用 idealHeight.fixedSize 一起Spacer 的修饰符年代:

Spacer()
.frame(minHeight: 10, idealHeight: 100, maxHeight: 600)
.fixedSize()

关于ios - swift 用户界面。如何设置 Spacer 的收缩行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59135719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com