Skip to content

Instantly share code, notes, and snippets.

@smrfeld
Created April 12, 2022 21:33
Show Gist options
  • Save smrfeld/dd2c981980df39d2ff0104827f5eb4e1 to your computer and use it in GitHub Desktop.
Save smrfeld/dd2c981980df39d2ff0104827f5eb4e1 to your computer and use it in GitHub Desktop.
Circle animation not working
struct ContentView: View {
@State var angle: Float = Float.pi / 2.0
let radius: Float = 200
var body: some View {
ZStack {
Circle()
.strokeBorder(.black, lineWidth: 2)
.foregroundColor(.clear)
.frame(width: CGFloat(2*radius), height: CGFloat(2*radius))
.position(x: 400, y: 400)
Circle()
.frame(width: 50, height: 50)
.foregroundColor(.blue)
.position(x: CGFloat(400 + radius * cos(angle)), y: CGFloat(400 - radius * sin(angle)))
}
.frame(width: 800, height: 800)
.background(.white)
.onAppear {
withAnimation(.easeInOut(duration: 2.0)) { // withAnimation tells that states modified in closure are animated
angle = -Float.pi / 2.0
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment