2

I have added a CABasicAnimation on CAShapeLayer.Now in this animation my CAShapeLayer create an arc on circle with animation.

Now what I want when this animation proceed count of label should increase with a sync to animation of CAShapeLayer. PLease how can I do it?

let animation = CABasicAnimation(keyPath: "strokeEnd")
//animation.delegate = self
animation.duration = 2
animation.fromValue = 0
animation.toValue = 0.7 // changed here
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.isRemovedOnCompletion = false

progressCircle.add(animation, forKey: "ani")

Here ProgressCircle is the CAShapeLayer.

I used below code for increement label count with animation but it does not match with the animation.

func incrementLabel(to endValue: Int) {
        let duration: Double = 1.0 //seconds
        DispatchQueue.global().async {
            for i in 0 ..< (endValue + 1) {
                let sleepTime = UInt32(duration/Double(endValue) * 1000000.0)
                usleep(sleepTime)
                DispatchQueue.main.async {
                    self.label.text = "\(i)"
                }
            }
        }
    }
Amit
  • 4,837
  • 5
  • 31
  • 46
TechChain
  • 8,404
  • 29
  • 103
  • 228

0 Answers0