Created
June 30, 2020 10:27
-
-
Save MickaelCruzDB/b42598dd5b264432c26c68e93cebd37f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 createPulse() { | |
for _ in 0...2 { | |
let circularPath = UIBezierPath(arcCenter: .zero, radius: UIScreen.main.bounds.size.width/2.0, startAngle: 0, endAngle: 2 * .pi, clockwise: true) | |
let pulseLayer1 = CAShapeLayer() | |
pulseLayer1.path = circularPath.cgPath | |
pulseLayer1.fillColor = UIColor.clear.cgColor | |
pulseLayer1.lineCap = CAShapeLayerLineCap.round | |
pulseLayer1.position = CGPoint(x: view.frame.size.width/2.0 - 2, y: view.frame.size.height/2.0) | |
pulseLayer1.masksToBounds = false | |
pulseLayer1.shouldRasterize = true | |
//Shadow 1 | |
pulseLayer1.shadowOpacity = 1 | |
pulseLayer1.shadowColor = UIColor(red: 199/255, green: 216/255, blue: 229/255, alpha: 1.0).cgColor | |
pulseLayer1.shadowOffset = CGSize(width: 11, height: 1) | |
pulseLayer1.shadowRadius = 16 | |
pulseLayer1.shadowPath = UIBezierPath(roundedRect: circularPath.bounds, cornerRadius: UIScreen.main.bounds.size.width/2.0).cgPath | |
let pulseLayer2 = CAShapeLayer() | |
pulseLayer2.path = circularPath.cgPath | |
pulseLayer2.fillColor = UIColor.clear.cgColor | |
pulseLayer2.lineCap = CAShapeLayerLineCap.round | |
pulseLayer2.position = CGPoint(x: 0, y: 0) | |
pulseLayer2.masksToBounds = false | |
pulseLayer2.shouldRasterize = true | |
//Shadow 2 | |
pulseLayer2.shadowOpacity = 1 | |
pulseLayer2.shadowColor = UIColor(red: 244/255, green: 248/255, blue: 251/255, alpha: 0.5).cgColor | |
pulseLayer2.shadowOffset = CGSize(width: -10, height: 0) | |
pulseLayer2.shadowRadius = 10 | |
pulseLayer2.shadowPath = UIBezierPath(roundedRect: circularPath.bounds, cornerRadius: UIScreen.main.bounds.size.width/2.0).cgPath | |
let pulseLayer3 = CAShapeLayer() | |
pulseLayer3.path = circularPath.cgPath | |
pulseLayer3.fillColor = UIColor.clear.cgColor | |
pulseLayer3.lineCap = CAShapeLayerLineCap.round | |
pulseLayer3.position = CGPoint(x: 0, y: 0) | |
pulseLayer3.masksToBounds = false | |
pulseLayer3.shouldRasterize = true | |
//Shadow 3 | |
pulseLayer3.shadowOpacity = 1 | |
pulseLayer3.shadowColor = UIColor(red: 246/255, green: 251/255, blue: 255/255, alpha: 0.25).cgColor | |
pulseLayer3.shadowOffset = CGSize(width: -10, height: -36) | |
pulseLayer3.shadowRadius = 33 | |
pulseLayer3.shadowPath = UIBezierPath(roundedRect: circularPath.bounds, cornerRadius: UIScreen.main.bounds.size.width/2.0).cgPath | |
let pulseLayer4 = CAShapeLayer() | |
pulseLayer4.path = circularPath.cgPath | |
pulseLayer4.fillColor = UIColor.clear.cgColor | |
pulseLayer4.lineCap = CAShapeLayerLineCap.round | |
pulseLayer4.position = CGPoint(x: 0, y: 0) | |
pulseLayer4.masksToBounds = false | |
pulseLayer4.shouldRasterize = true | |
//Shadow 4 | |
pulseLayer4.shadowOpacity = 1 | |
pulseLayer4.shadowColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.2).cgColor | |
pulseLayer4.shadowOffset = CGSize(width: -8, height: -8) | |
pulseLayer4.shadowRadius = 14 | |
pulseLayer4.shadowPath = UIBezierPath(roundedRect: circularPath.bounds, cornerRadius: UIScreen.main.bounds.size.width/2.0).cgPath | |
pulseLayer1.addSublayer(pulseLayer2) | |
pulseLayer1.addSublayer(pulseLayer3) | |
pulseLayer1.addSublayer(pulseLayer4) | |
self.view.layer.addSublayer(pulseLayer1) | |
self.pulseLayers.append(pulseLayer1) | |
} | |
DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) { | |
self.animatePulse(index: 0) | |
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) { | |
self.animatePulse(index: 1) | |
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { | |
self.animatePulse(index: 2) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment