【发布时间】:2020-10-27 11:47:37
【问题描述】:
我的对齐在 xcode12 ios14 中不起作用,但是,我在 xcode11.5 中有相同的代码,一切都很好。每当我将 .frame viewModifier 添加到内容对齐时,它不在中心,是错误还是 API 已更改?这是代码:请在 xcode12 中查看,仅限 ios14。
struct ContentView: View {
var body : some View {
GeometryReader { geo in
Capsule()
.fill(Color.red)
.frame(height: 50)
}
}
}
这也不行:
struct ContentView: View {
var body : some View {
ZStack(alignment: .center) {
GeometryReader { geo in
Capsule()
.fill(Color.red)
.frame(height: 50)
}
}
}
}
这不起作用:
struct ContentView: View {
var body : some View {
ZStack(alignment: .center) {
GeometryReader { geo in
Capsule()
.fill(Color.red)
.frame(height: 50, alignment: .center)
}
}
}
}
每当我删除 GeometryReader 时一切正常,但我想要 GeometryReader
【问题讨论】:
-
是的,
GeometryReader的行为不同,但很难说哪个更正确。我建议不要依赖 implicit 布局,而是根据需要明确地进行布局。向 Apple 提交反馈,如果需要,他们可能会回复。 -
我应该回到xcode11.5吗?我正在遵循他们使用xcode12的教程,什么是最佳解决方案
-
是xcode12还是swiftui2.0还是ios14有问题?
标签: swift swiftui alignment frame ios14