I'm trying to create my custom activity indicator thing, this is what I have so far:
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
let center = view.center
let circularPath = UIBezierPath(arcCenter: center, radius: 180, startAngle: -CGFloat.pi / 2, endAngle: 2 * CGFloat.pi, clockwise: true)
shapeLayer.path = circularPath.cgPath
shapeLayer.strokeColor = UIColor.green.cgColor
shapeLayer.lineWidth = 20
shapeLayer.lineCap = CAShapeLayerLineCap.round
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeEnd = 0
view.layer.addSublayer(shapeLayer)
UIView.animate(withDuration: 10, delay: 0, options: [], animations: {
let basicAnimation = CABasicAnimation(keyPath: "strokeEnd")
basicAnimation.toValue = 1
basicAnimation.duration = 2
basicAnimation.fillMode = CAMediaTimingFillMode.forwards
basicAnimation.isRemovedOnCompletion = false
self.shapeLayer.add(basicAnimation, forKey: "key")
}) { (finished) in
if finished {
self.shapeLayer.removeFromSuperlayer()
}
}
}
So, after the animation is completed, I will present a new controller or something. The issue is that the completion is being called immediately. So, how I can wait for