Skip to content

Instantly share code, notes, and snippets.

@alladinian
Created March 23, 2020 14:44
Show Gist options
  • Save alladinian/6407738c14ff1a63d1b35af030b101c7 to your computer and use it in GitHub Desktop.
Save alladinian/6407738c14ff1a63d1b35af030b101c7 to your computer and use it in GitHub Desktop.
struct TimingCurveView: View {
@State var value: CGFloat = 0
@State var cp1: RelativePoint = .zero
@State var cp2: RelativePoint = .zero
let timer = Timer.publish(every: 2, on: .main, in: .common).autoconnect()
var animation: Animation {
Animation.timingCurve(
Double(cp1.x),
Double(1 - cp1.y),
Double(cp2.x),
Double(1 - cp2.y),
duration: 2
)
}
var body: some View {
VStack {
CurveEditorView(controlPoint1: $cp1, controlPoint2: $cp2)
.aspectRatio(contentMode: .fill)
Spacer()
GeometryReader { reader in
Circle()
.position(x: 0, y: 6)
.offset(x: self.value * reader.size.width, y: 0)
.frame(height: 12)
}.frame(height: 40)
}
.onReceive(timer) { _ in
self.value = 0
withAnimation(self.animation) {
self.value = 1
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment