Skip to content

Commit

Permalink
Convert animationDuration to computed property (fixes #196) [swift]
Browse files Browse the repository at this point in the history
  • Loading branch information
cbpowell committed Sep 8, 2017
1 parent 3f22ffa commit d40d160
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions Sources/Swift/MarqueeLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,19 @@ open class MarqueeLabel: UILabel, CAAnimationDelegate {
@IBInspectable open var animationDelay: CGFloat = 1.0


/** The read-only duration of the scroll animation (not including delay).
/** The read-only/computed duration of the scroll animation (not including delay).

The value of this property is calculated from the value set to the `speed` property. If a .duration value is
used to set the label animation speed, this value will be equivalent.
The value of this property is calculated from the value set to the `speed` property. If a duration-type speed is
used to set the label animation speed, `animationDuration` will be equivalent to that value.
*/
private(set) public var animationDuration: CGFloat = 0.0
public var animationDuration: CGFloat {
switch self.speed {
case .rate(let rate):
return CGFloat(fabs(self.awayOffset) / rate)
case .duration(let duration):
return duration
}
}

//
// MARK: - Class Functions and Helpers
Expand Down Expand Up @@ -607,16 +614,6 @@ open class MarqueeLabel: UILabel, CAAnimationDelegate {

// Label DOES need to scroll

// Recompute the animation duration
animationDuration = {
switch self.speed {
case .rate(let rate):
return CGFloat(fabs(self.awayOffset) / rate)
case .duration(let duration):
return duration
}
}()

// Spacing between primary and second sublabel must be at least equal to leadingBuffer, and at least equal to the fadeLength
let minTrailing = max(max(leadingBuffer, trailingBuffer), fadeLength)

Expand Down

0 comments on commit d40d160

Please sign in to comment.