Skip to content

Instantly share code, notes, and snippets.

@mkj-is
Last active January 24, 2017 12:10
Show Gist options
  • Save mkj-is/bf98a5eddfe34e9a3e61045c6c98464b to your computer and use it in GitHub Desktop.
Save mkj-is/bf98a5eddfe34e9a3e61045c6c98464b to your computer and use it in GitHub Desktop.
Hue color animation
// We will offset the starting hue of every letter a bit
let startHue = CGFloat(offset) / CGFloat(layers.count)
// And also we offset the end hue a bit
// (We need to check if the hue is not larger than 1, then we use the remainder after dividing by 1 as a correct hue value)
let endHue = (CGFloat(offset + 1) / CGFloat(layers.count + 1)).truncatingRemainder(dividingBy: 1)
// And we create the colors from the hue values
let startColor = UIColor(hue: startHue, saturation: 1, brightness: 1, alpha: 1)
let endColor = UIColor(hue: endHue, saturation: 1, brightness: 1, alpha: 1)
// Finally, we create the animation similarly to the stroke end animation
let colorAnimation = CABasicAnimation(keyPath: "strokeColor")
colorAnimation.fromValue = startColor.cgColor
colorAnimation.toValue = endColor.cgColor
colorAnimation.beginTime = duration * CFTimeInterval(offset) + delay
colorAnimation.duration = duration
colorAnimation.autoreverses = true
colorAnimation.fillMode = kCAFillModeForwards
// In the end we add the color animation to the group already containing the stroke animation
group.animations += colorAnimation
@mkj-is
Copy link
Author

mkj-is commented Jan 16, 2017

@mkj-is
Copy link
Author

mkj-is commented Jan 16, 2017

duha-blog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment