CAShapeLayer loop animation

forgive me for yet another post on the subject, but I’m close to the solution, but I can’t find it. Yet, I am sure to be close.

Let me explain: I want to animate these blessed svg images, and I can. The thing that I can’t to do is make these animations cycle. ie, just end the animation of the last stroke, all will reset and start again.

please! Help me. I am going crazy

this is the code that I use
for svg you can download from KanjiVG site the files and use any of the files

let array = SVGBezierPath.pathsFromSVG(at: Bundle.main.url(forResource: "test", withExtension: "svg")!)
            
            var index = 0
            
            for var path:SVGBezierPath in array {
                let layer = CAShapeLayer()
                layer.path = path.cgPath
                
                layer.lineWidth = CGFloat((path.svgAttributes["stroke-width"] as! NSString).floatValue)
                layer.strokeColor = UIColor.clear.cgColor
                layer.fillColor = UIColor.clear.cgColor
                
                let pathAnimation:CABasicAnimation = CABasicAnimation(keyPath: "strokeEnd")
                pathAnimation.delegate = self
                pathAnimation.duration = 0.5
                pathAnimation.beginTime = CACurrentMediaTime() + pathAnimation.duration * Double(index)
                pathAnimation.fromValue = NSNumber(floatLiteral: 0.0)
                pathAnimation.toValue = NSNumber(floatLiteral: 1.0)
                pathAnimation.isRemovedOnCompletion = true
                //pathAnimation.autoreverses = true
                pathAnimation.fillMode = kCAFillModeBackwards
                pathAnimation.isCumulative = true
                
                pathAnimation.repeatCount = .greatestFiniteMagnitude
                layer.add(pathAnimation, forKey: "strokeEnd")
                self.layersArray.append(layer)
                
                index += 1
            }
            
            for var layer:CAShapeLayer in self.layersArray {
                self.svgImageView.layer.addSublayer(layer)
                //self.kanjiAnimationImageView.layer.addSublayer(layer)
            }
func animationDidStart(_ anim: CAAnimation) {
        let layer:CAShapeLayer = layersArray[indexAnimStart]
        layer.strokeColor = UIColor.black.cgColor
        indexAnimStart += 1
    }

where I make mistake???

@rufy. Thanks very much for your question, and my apologies for the delayed response. What I would recommend is to post lengthy technical questions like this on www.stackoverflow.com, and I can almost guarantee you that you will get a solution within 24 hours. :slight_smile:

I hope this helps!

All the best!