Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoiphonedev/76f489e02b052067e25361c009dfc008 to your computer and use it in GitHub Desktop.
Save leoiphonedev/76f489e02b052067e25361c009dfc008 to your computer and use it in GitHub Desktop.
Adding scale and fade animation to the layer
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