curent working order
This commit is contained in:
parent
ee5f0dfdc2
commit
898877a051
@ -58,28 +58,23 @@ open class LoadingSpinner: View {
|
||||
}
|
||||
|
||||
struct Pose {
|
||||
let secondsSincePriorPose: CFTimeInterval
|
||||
let delay: CFTimeInterval
|
||||
let start: CGFloat
|
||||
let length: CGFloat
|
||||
init(_ secondsSincePriorPose: CFTimeInterval, _ start: CGFloat, _ length: CGFloat) {
|
||||
self.secondsSincePriorPose = secondsSincePriorPose
|
||||
self.start = start
|
||||
self.length = length
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This needs more attention
|
||||
class var poses: [Pose] {
|
||||
get {
|
||||
return [
|
||||
Pose(0.0, 0.000, 0.7),
|
||||
Pose(0.7, 0.500, 0.5),
|
||||
Pose(0.6, 1.000, 0.3),
|
||||
Pose(0.4, 1.500, 0.2),
|
||||
Pose(0.3, 1.875, 0.2),
|
||||
Pose(0.3, 2.250, 0.3),
|
||||
Pose(0.2, 2.625, 0.5),
|
||||
Pose(0.2, 3.000, 0.7)
|
||||
Pose(delay: 0.0, start: 0.000, length: 0.7),
|
||||
Pose(delay: 0.7, start: 0.500, length: 0.5),
|
||||
Pose(delay: 0.6, start: 1.000, length: 0.3),
|
||||
Pose(delay: 0.5, start: 1.500, length: 0.2),
|
||||
Pose(delay: 0.4, start: 1.875, length: 0.2),
|
||||
Pose(delay: 0.3, start: 2.250, length: 0.3),
|
||||
Pose(delay: 0.2, start: 2.600, length: 0.5),
|
||||
Pose(delay: 0.2, start: 3.000, length: 0.7)
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -92,19 +87,19 @@ open class LoadingSpinner: View {
|
||||
var strokeEnds = [CGFloat]()
|
||||
|
||||
let poses = Self.poses
|
||||
let totalSeconds = poses.reduce(0) { $0 + $1.secondsSincePriorPose }
|
||||
let totalSeconds = poses.reduce(0) { $0 + $1.delay }
|
||||
|
||||
for pose in poses {
|
||||
time += pose.secondsSincePriorPose
|
||||
time += pose.delay
|
||||
times.append(time / totalSeconds)
|
||||
start = pose.start
|
||||
rotations.append(start * 2 * CGFloat.pi)
|
||||
strokeEnds.append(pose.length)
|
||||
}
|
||||
|
||||
times.append(times.last!)
|
||||
rotations.append(rotations[0])
|
||||
strokeEnds.append(strokeEnds[0])
|
||||
// times.append(times.last ?? 1)
|
||||
// rotations.append(rotations[0])
|
||||
// strokeEnds.append(strokeEnds[0])
|
||||
|
||||
animateKeyPath(keyPath: "strokeEnd", duration: totalSeconds, times: times, values: strokeEnds)
|
||||
animateKeyPath(keyPath: "transform.rotation", duration: totalSeconds, times: times, values: rotations)
|
||||
@ -116,6 +111,7 @@ open class LoadingSpinner: View {
|
||||
animation.keyTimes = times as [NSNumber]?
|
||||
animation.values = values
|
||||
animation.calculationMode = .linear
|
||||
animation.timingFunction = CAMediaTimingFunction(name: .linear)
|
||||
animation.duration = duration
|
||||
animation.rotationMode = .rotateAuto
|
||||
animation.fillMode = .forwards
|
||||
@ -136,6 +132,7 @@ open class LoadingSpinner: View {
|
||||
}
|
||||
|
||||
func pauseAnimations() {
|
||||
|
||||
let pausedTime = layer.convertTime(CACurrentMediaTime(), from: nil)
|
||||
layer.speed = 0
|
||||
isHidden = true
|
||||
@ -143,6 +140,7 @@ open class LoadingSpinner: View {
|
||||
}
|
||||
|
||||
func resumeAnimations() {
|
||||
|
||||
let pausedTime = layer.timeOffset
|
||||
isHidden = false
|
||||
layer.speed = speed
|
||||
@ -153,11 +151,14 @@ open class LoadingSpinner: View {
|
||||
}
|
||||
|
||||
func stopAllAnimations() {
|
||||
|
||||
layer.removeAllAnimations()
|
||||
}
|
||||
|
||||
func pinWidthAndHeight(radius: CGFloat) {
|
||||
|
||||
let diameter: CGFloat = radius * 2 + lineWidth
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
heightAnchor.constraint(equalToConstant: diameter),
|
||||
widthAnchor.constraint(equalToConstant: diameter)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user