Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.