Skip to content

Instantly share code, notes, and snippets.

@tbatsuur
Created December 11, 2018 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbatsuur/bc04946cdec9feabd3a94a496e83b5a5 to your computer and use it in GitHub Desktop.
Save tbatsuur/bc04946cdec9feabd3a94a496e83b5a5 to your computer and use it in GitHub Desktop.
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