-
-
Save tbatsuur/bc04946cdec9feabd3a94a496e83b5a5 to your computer and use it in GitHub Desktop.
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 redCircleAnimation() { | |
let startingPoint = CGPoint(x: 0.0, y: DeviceScreen.main.centreY) | |
//Red view | |
self.redDotView.layer.cornerRadius = self.redDotView.frame.width/2 | |
self.redDotView.clipsToBounds = true | |
self.redDotView.center = startingPoint | |
//The path | |
let bezierPath = UIBezierPath() | |
bezierPath.move(to: startingPoint) | |
//OPTIONS | |
//Curve | |
bezierPath.addCurve(to: CGPoint(x: DeviceScreen.main.width, y: DeviceScreen.main.centreY), controlPoint1: CGPoint(x: DeviceScreen.main.centreX, y: (DeviceScreen.main.centreY + 50.0)), controlPoint2: CGPoint(x: DeviceScreen.main.centreX, y: (DeviceScreen.main.centreY - 50.0))) | |
bezierPath.addLine(to: CGPoint(x: DeviceScreen.main.width, y: 0.0)) | |
bezierPath.addLine(to: CGPoint(x: 0.0, y: 0.0)) | |
bezierPath.addLine(to: startingPoint) | |
//The animation | |
let animation = CAKeyframeAnimation(keyPath: #keyPath(CALayer.position)) | |
animation.path = bezierPath.cgPath | |
animation.calculationMode = CAAnimationCalculationMode.paced | |
animation.repeatCount = HUGE | |
animation.duration = 5.0 | |
//The layer | |
let shapeLayer = CAShapeLayer() | |
shapeLayer.path = bezierPath.cgPath | |
shapeLayer.fillColor = UIColor.clear.cgColor | |
shapeLayer.strokeColor = UIColor.red.cgColor | |
shapeLayer.lineWidth = 1.0 | |
view.layer.addSublayer(shapeLayer) | |
self.redDotView.layer.add(animation, forKey: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment