I need to get frames for multiple views inside a VStack. I think using the GeometryReader
but it returns the necessary parameters only for the parent. How can I get these parameters for each view on the screenshot below?
Asked
Active
Viewed 1,938 times
2

vikingosegundo
- 52,040
- 14
- 137
- 178

yuraist
- 121
- 2
- 9
-
https://stackoverflow.com/a/60495440/12233264 this might help you – KevinP Apr 20 '20 at 20:12
1 Answers
2
We can use the GeometryReader inside the overlay on needed views and store necessary frames in an array or as separate variables.
ForEach(0..<n) { number in
YourView()
.overlay(
GeometryReader { geometry in
Color.clear
.onAppear {
self.buttonFrames[number] = geometry.frame(in: .global)
}
}
)
}
For more details, you can check this source: https://github.com/twostraws/SwiftOnSundays/blob/master/020%20Switcharoo/Project/Switcharoo/ContentView.swift and the full tutorial: https://www.youtube.com/watch?v=ffV_fYcFoX0

yuraist
- 121
- 2
- 9