Last active
March 3, 2019 10:22
-
-
Save mkj-is/67dfd9508f3d0f72611c36bcadfcf72b to your computer and use it in GitHub Desktop.
Stroke animations on shape layers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://blog.thefuntasty.com/swift-stroke-animations-e1b864917255