I am a bit confused on the proper usage of GeometryReader. For example, I have a SwiftUI View, like so;
This positions my VStack perfectly in the middle of the device, both horizontally and vertically. At some point, I may need to know the width of the View's frame, and therefore, want to implement a GeometryReader;
While I now have access to the View's frame using the GeometryProxy, my VStack is now moved to the top left corner of the device.
Why is this? Subsequently, is there any way to get the size of the View without having the layout altered?
Code Block var body: some View { VStack { Text("Hello, World!") .background(Color.red) Text("More Text") .background(Color.blue) } }
This positions my VStack perfectly in the middle of the device, both horizontally and vertically. At some point, I may need to know the width of the View's frame, and therefore, want to implement a GeometryReader;
Code Block var body: some View { GeometryReader { geometry in VStack { Text("Hello, World!") .background(Color.red) Text("More Text") .background(Color.blue) } } }
While I now have access to the View's frame using the GeometryProxy, my VStack is now moved to the top left corner of the device.
Why is this? Subsequently, is there any way to get the size of the View without having the layout altered?