Hi,
I've created an effect that after clicking on the "Hello, world!" button, it has to move (first move is when the user taps on it), and then it has to move again, but this time without any interaction, and it does. But the problem is that when I click again on it, it goes back and then returns to the same position, I can't understand how to solve this issue.
This is my code:
import SwiftUI
public struct ContentView: View {
@State var xPos: CGFloat = 300
@State var yPos: CGFloat = 400
@State var size: CGFloat = 120
public var body: some View {
ZStack {
Image("background")
.resizable()
.frame(width: 700, height: 500)
.padding()
.overlay {
Button(action: {
xPos = 170
yPos = 310
size = 60
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
xPos = 700
}
}) {
Text("Hello, world!")
.font(.system(size: size))
.position(x: xPos, y: yPos)
}
.animation(.spring)
}
}
}
}
Can anyone help me?
Thanks in advance!