Open IamRohitSinghDhakad opened 3 years ago
I want to animate arc while drawing on the view. I tried with CAShapeLayer and CABasicAnimation but no luck.
This is what I tried. func createArcWithAnimate(startAngle: CGFloat, endAngle: CGFloat, arcCap: CGLineCap, strokeColor: UIColor, center:CGPoint) { let slayer = CAShapeLayer() let center = center let radius: CGFloat = max(bounds.width, bounds.height)/2 - self.frame.width/20 let startAngle: CGFloat = startAngle let endAngle: CGFloat = endAngle slayer.path = UIBezierPath(arcCenter: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true).cgPath // slayer.lineWidth = 15.0 slayer.lineCap = CAShapeLayerLineCap.round slayer.strokeColor = UIColor.blue.cgColor slayer.fillColor = UIColor.clear.cgColor layer.addSublayer(slayer) slayer.strokeEnd = 0.0
let animation = CABasicAnimation(keyPath: "transform.rotation.z") animation.duration = 05.0 //Customize the time of your animation here. animation.fromValue = startAngle animation.toValue = endAngle animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear) slayer.strokeEnd = 1.0 slayer.add(animation, forKey: nil) }
I want to animate arc while drawing on the view. I tried with CAShapeLayer and CABasicAnimation but no luck.
This is what I tried. func createArcWithAnimate(startAngle: CGFloat, endAngle: CGFloat, arcCap: CGLineCap, strokeColor: UIColor, center:CGPoint) { let slayer = CAShapeLayer() let center = center let radius: CGFloat = max(bounds.width, bounds.height)/2 - self.frame.width/20 let startAngle: CGFloat = startAngle let endAngle: CGFloat = endAngle slayer.path = UIBezierPath(arcCenter: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true).cgPath // slayer.lineWidth = 15.0 slayer.lineCap = CAShapeLayerLineCap.round slayer.strokeColor = UIColor.blue.cgColor slayer.fillColor = UIColor.clear.cgColor layer.addSublayer(slayer) slayer.strokeEnd = 0.0