Created
January 17, 2020 17:47
-
-
Save chriseidhof/5bfa9d62af9176136141d20977989600 to your computer and use it in GitHub Desktop.
This file contains 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
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