A Text
element inside a ZStack(alignment: .bottom)
is displayed at the bottom of the container (as expected). Tho, if the same ZStack
is inside a GeometryReader
, the alignment does not behave the same anymore.
This code:
var body: some View {
ZStack(alignment: .bottom) {
VStack {
Text("Outside geo")
}
GeometryReader { geo in
ZStack(alignment: .bottom) {
VStack {
Text("Inside geo")
}
}.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}.frame(maxWidth: .infinity, maxHeight: .infinity)
}
produces this result:
If I'd want the "inside geo" to be placed at the bottom too, I'd have to add alignment: .bottom
inside its parent ZStack .frame(...) modifier.
What's the background for this behavior? Why can I use ZStack(alignment: ...)
in one case, but have to use ZStack {...}.frame(alignment: ...)
in the other to achieve the same result?