Skip to content

Instantly share code, notes, and snippets.

@smrfeld
Created April 12, 2022 21:23
Show Gist options
  • Select an option

  • Save smrfeld/2f6051b8c0b50b8f48441d648ac27dd0 to your computer and use it in GitHub Desktop.

Select an option

Save smrfeld/2f6051b8c0b50b8f48441d648ac27dd0 to your computer and use it in GitHub Desktop.
Animation V2
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