Skip to content

Commit

Permalink
Merge pull request EFPrefix#3 from rwinzhang/master
Browse files Browse the repository at this point in the history
Fix timer fps on iOS10 and crash when calling countFromCurrentValueTo
  • Loading branch information
EyreFree authored May 24, 2017
2 parents 4712d0f + 20b036c commit f9e3713
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions EFCountingLabel/Classes/EFCountingLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class EFCountingLabel: UILabel {

private var startingValue: CGFloat!
private var destinationValue: CGFloat!
private var progress: TimeInterval!
private var progress: TimeInterval = 0
private var lastUpdate: TimeInterval!
private var totalTime: TimeInterval!
private var easingRate: CGFloat!
Expand Down Expand Up @@ -128,7 +128,7 @@ public class EFCountingLabel: UILabel {

let timer = CADisplayLink(target: self, selector: #selector(EFCountingLabel.updateValue(_:)))
if #available(iOS 10.0, *) {
timer.preferredFramesPerSecond = 2
timer.preferredFramesPerSecond = 30
} else {
timer.frameInterval = 2
}
Expand All @@ -154,7 +154,9 @@ public class EFCountingLabel: UILabel {
}

public func currentValue() -> CGFloat {
if self.progress >= self.totalTime {
if self.progress == 0 {
return 0
} else if self.progress >= self.totalTime {
return self.destinationValue
}

Expand Down

0 comments on commit f9e3713

Please sign in to comment.