Below I have three Text views, the location of View 3 will be dynamic every time the app loads, and what I would like to be able to do is animate View 2 to the exact position of View 3 regardless of where View 3 is on the screen.
I found this thread but I'm not sure how to use ReometryReader to accomplish what I need.
How can I get the current position of View 3?
How can I assign the x and y position of the View 3 to xPosition and yPosition respectively inside the withAnimation method?
struct PositioningViews: View {
@State private var xPosition:CGFloat = 0
@State private var yPosition:CGFloat = 0
var body: some View {
HStack {
Text("View 1")
.background(.purple)
Text("View 2")
.background(.orange)
.offset(x: xPosition, y: yPosition)
.onAppear {
withAnimation(Animation.easeOut(duration: 0.3).delay(0.5)) {
self.xPosition = 50
self.yPosition = 0
}
}
Text("View 3")
.background(.blue)
}
}
}