Skip to content

Commit

Permalink
Re-implement continuous end-loop fade timing [swift]
Browse files Browse the repository at this point in the history
  • Loading branch information
cbpowell committed Jun 10, 2017
1 parent 8270a89 commit 2594f39
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions Sources/Swift/MarqueeLabel.swift
Expand Up @@ -613,11 +613,20 @@ open class MarqueeLabel: UILabel, CAAnimationDelegate {
awayOffset = (homeLabelFrame.size.width + minTrailing)
}

// Find when the lead label will be totally offscreen
let offsetDistance = awayOffset
let offscreenAmount = homeLabelFrame.size.width
let startFadeFraction = fabs(offscreenAmount / offsetDistance)
// Find when the animation will hit that point
let startFadeTimeFraction = timingFunctionForAnimationCurve(animationCurve).durationPercentageForPositionPercentage(startFadeFraction, duration: (animationDelay + animationDuration))
let startFadeTime = startFadeTimeFraction * animationDuration

sequence = scrollSteps ?? [
ScrollStep(timeStep: 0.0, position: .home, edgeFades: .trailing), // Starting point, at home, with trailing fade
ScrollStep(timeStep: animationDelay, position: .home, edgeFades: .trailing), // Delay at home, maintaining fade state
FadeStep(timeStep: 0.2, edgeFades: [.leading, .trailing]), // 0.2 sec after delay ends, fade leading edge in as well
FadeStep(timeStep: -0.1, edgeFades: [.leading, .trailing]), // Maintain fade state until 0.1 sec before reaching end of scroll animation
FadeStep(timeStep: 0.2, edgeFades: [.leading, .trailing]), // 0.2 sec after scroll start, fade leading edge in as well
FadeStep(timeStep: (startFadeTime - animationDuration), // Maintain fade state until just before reaching end of scroll animation
edgeFades: [.leading, .trailing]),
ScrollStep(timeStep: animationDuration, timingFunction: animationCurve, // Ending point (back at home), with animationCurve transition, with trailing fade
position: .away, edgeFades: .trailing)
]
Expand Down Expand Up @@ -959,19 +968,6 @@ open class MarqueeLabel: UILabel, CAAnimationDelegate {
// Create new animation
let animation = CAKeyframeAnimation(keyPath: "colors")

// Find when the lead label will be totally offscreen
// TODO
// let offsetDistance = awayOffset
// let startFadeFraction = fabs((sublabel.bounds.size.width + leadingBuffer) / offsetDistance)
// // Find when the animation will hit that point
// let startFadeTimeFraction = timingFunction.durationPercentageForPositionPercentage(startFadeFraction, duration: totalDuration)
// let startFadeTime = delay + CGFloat(startFadeTimeFraction) * interval

// Define values
// Get current layer values
//let mask = maskLayer?.presentation()
//let currentValues = mask?.colors as? [CGColor]

animation.values = fadeKeyValues
animation.keyTimes = fadeKeyTimes
animation.timingFunctions = fadeTimingFunctions
Expand Down

0 comments on commit 2594f39

Please sign in to comment.