Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
Created January 17, 2020 17:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriseidhof/5bfa9d62af9176136141d20977989600 to your computer and use it in GitHub Desktop.
Save chriseidhof/5bfa9d62af9176136141d20977989600 to your computer and use it in GitHub Desktop.
import SwiftUI
final class Ticks: ObservableObject {
@Published var seconds: Int = 58
func start() {
Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { [unowned self] _ in
withAnimation(.easeInOut) { self.seconds += 1 }
if self.seconds == 60 {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .milliseconds(350)) {
withAnimation(.none) { self.seconds = 0 }
}
}
})
}
}
struct ContentView: View {
@ObservedObject var ticks = Ticks()
var body: some View {
return ZStack {
Rectangle()
.frame(width: 2, height: 50)
.offset(y: -25)
.rotationEffect(Angle(degrees: Double(ticks.seconds) * 6))
.onAppear {
self.ticks.start()
}
Circle().frame(width: 5, height: 5)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment