Created
April 12, 2022 21:23
-
-
Save smrfeld/2f6051b8c0b50b8f48441d648ac27dd0 to your computer and use it in GitHub Desktop.
Animation V2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct ContentView: View { | |
| @State var xpos: CGFloat = 400 | |
| @State var ypos: CGFloat = 200 | |
| var body: some View { | |
| ZStack { | |
| Circle() | |
| .frame(width: 50, height: 50) | |
| .foregroundColor(.blue) | |
| .position(x: xpos, y: ypos) | |
| } | |
| .frame(width: 800, height: 800) | |
| .background(.white) | |
| .onAppear { | |
| withAnimation(.easeInOut(duration: 2.0)) { // withAnimation tells that states modified in closure are animated | |
| ypos = 600 | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment