Created
April 12, 2022 21:33
-
-
Save smrfeld/dd2c981980df39d2ff0104827f5eb4e1 to your computer and use it in GitHub Desktop.
Circle animation not working
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 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