Skip to content

Instantly share code, notes, and snippets.

@donguri9
Last active June 22, 2021 11:28
Show Gist options
  • Save donguri9/c6e8fd9901effb8f0ddc3d91726eadbf to your computer and use it in GitHub Desktop.
Save donguri9/c6e8fd9901effb8f0ddc3d91726eadbf to your computer and use it in GitHub Desktop.
SwiftUI Animation
import SwiftUI
var sw = UIScreen.main.bounds.width
struct ContentView: View {
@State var drive:Bool = true
var body: some View {
ZStack{
Circle()
.stroke(style: StrokeStyle(lineWidth: 20))
.frame(width: sw*0.8, height: sw*0.8)
.foregroundColor(.gray)
Circle()
.stroke(style: StrokeStyle(lineWidth: 4,dash:[20,20]))
.frame(width: sw*0.8, height: sw*0.8)
.foregroundColor(.white)
Image("car")
.resizable()
.frame(width: 30, height: 30)
.offset(x:-sw*0.4,y:0)
.rotationEffect(.degrees(drive ? 360:0))
.animation(Animation.linear(duration: 4).repeatForever(autoreverses: false))
.onAppear{
self.drive.toggle()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment