Skip to content

Instantly share code, notes, and snippets.

@mkj-is
Last active March 3, 2019 10:22
Show Gist options
  • Save mkj-is/67dfd9508f3d0f72611c36bcadfcf72b to your computer and use it in GitHub Desktop.
Save mkj-is/67dfd9508f3d0f72611c36bcadfcf72b to your computer and use it in GitHub Desktop.
Stroke animations on shape layers
// Set duration for single animation
let duration: TimeInterval = 2
// Enumerate all the layers
layers.enumerated().forEach { offset, layer in
// Create animation for each layer
let animation = CABasicAnimation(keyPath: "strokeEnd")
// Begin each animation after the one before
animation.beginTime = duration * CFTimeInterval(offset) + delay
animation.toValue = 1
animation.duration = duration
animation.fillMode = kCAFillModeForwards
// Create animation group with the stroke basic animation
let group = CAAnimationGroup()
group.animations = [animation]
group.isRemovedOnCompletion = false
group.duration = CFTimeInterval(layers.count + 1) * duration
group.repeatCount = .infinity
group.autoreverses = true
group.fillMode = kCAFillModeForwards
// Add the animation group to the letter layer
layer.add(group, forKey: "group")
}
@mkj-is
Copy link
Author

mkj-is commented Jan 16, 2017

@mkj-is
Copy link
Author

mkj-is commented Jan 16, 2017

ft-blog-logo

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