Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CircularSpinner/Classes/CircularSpinner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ open class CircularSpinner: UIView {
fileprivate var progressCircleLayer = CAShapeLayer()

var indeterminateDuration: Double = 1.5
fileprivate static let determinateDuration: Double = 0.66

fileprivate var startAngle: CGFloat {
return CGFloat(M_PI_2)
Expand Down Expand Up @@ -275,19 +276,23 @@ open class CircularSpinner: UIView {


// MARK: - update
open class func setValue(_ value: Float, animated: Bool) {
open class func setValue(_ value: Float, animated: Bool, duration: Double) {
let spinner = CircularSpinner.sharedInstance
guard spinner.type == .determinate else { return }

spinner.value = value
spinner.updateTitleLabel()
spinner.setStrokeEnd(animated: animated) {
spinner.setStrokeEnd(animated: animated, duration: duration) {
if value >= 1 {
CircularSpinner.hide()
}
}
}

open class func setValue(_ value: Float, animated: Bool) {
setValue(value, animated: animated, duration: determinateDuration)
}

fileprivate func updateTitleLabel() {
let spinner = CircularSpinner.sharedInstance

Expand All @@ -298,7 +303,7 @@ open class CircularSpinner: UIView {
}
}

fileprivate func setStrokeEnd(animated: Bool, completed: (() -> Void)? = nil) {
fileprivate func setStrokeEnd(animated: Bool, duration: Double, completed: (() -> Void)? = nil) {
let spinner = CircularSpinner.sharedInstance

CATransaction.begin()
Expand All @@ -308,7 +313,7 @@ open class CircularSpinner: UIView {
})

let strokeAnimation = CABasicAnimation(keyPath: "strokeEnd")
strokeAnimation.duration = animated ? 0.66 : 0
strokeAnimation.duration = animated ? duration : 0.0
strokeAnimation.repeatCount = 1
strokeAnimation.fromValue = oldStrokeEnd ?? 0
strokeAnimation.toValue = spinner.value
Expand Down