Created
August 5, 2018 10:14
-
-
Save leoiphonedev/76f489e02b052067e25361c009dfc008 to your computer and use it in GitHub Desktop.
Adding scale and fade animation to the layer
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
func animatePulsatingLayerAt(index:Int) { | |
//Giving color to the layer | |
pulseArray[index].strokeColor = UIColor.darkGray.cgColor | |
//Creating scale animation for the layer, from and to value should be in range of 0.0 to 1.0 | |
// 0.0 = minimum | |
//1.0 = maximum | |
let scaleAnimation = CABasicAnimation(keyPath: "transform.scale") | |
scaleAnimation.fromValue = 0.0 | |
scaleAnimation.toValue = 0.9 | |
//Creating opacity animation for the layer, from and to value should be in range of 0.0 to 1.0 | |
// 0.0 = minimum | |
//1.0 = maximum | |
let opacityAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.opacity)) | |
opacityAnimation.fromValue = 0.9 | |
opacityAnimation.toValue = 0.0 | |
//Grouping both animations and giving animation duration, animation repat count | |
let groupAnimation = CAAnimationGroup() | |
groupAnimation.animations = [scaleAnimation, opacityAnimation] | |
groupAnimation.duration = 2.3 | |
groupAnimation.repeatCount = .greatestFiniteMagnitude | |
groupAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) | |
//adding groupanimation to the layer | |
pulseArray[index].add(groupAnimation, forKey: "groupanimation") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment