CAShapeLayer strokeStart and strokeEnd positions

I have this piece of code:

let arcPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, frame.width, frame.height)) circleLayer = CAShapeLayer() circleLayer.path = arcPath.CGPath circleLayer.fillColor = UIColor.clearColor().CGColor circleLayer.strokeColor = UIColor.blueColor().CGColor circleLayer.lineWidth = 5.0; circleLayer.strokeStart = 0 circleLayer.strokeEnd = 0.7 

which is as follows:

enter image description here

As you can see, the arc starts on the right side of the circle. I would like to draw an arc starting at the top. How can I do it? Do I need to rotate all this by -90 degrees to accomplish what I'm trying to do?

Thanks.

+5
source share
2 answers

You can create a path like this

 let bezierPath = UIBezierPath(arcCenter:CGPointMake(100,100), radius:40, startAngle: CGFloat(M_PI_2) * 3.0, endAngle:CGFloat(M_PI_2) * 3.0 + CGFloat(M_PI) * 2.0, clockwise: true) 

Sceenshot

cy9Cd.png

+10
source

I think that for this task it is enough to subtract 90 * M_PI / 180 from your original startAngle and endAngle .

God knows why Apple decides to treat 90 degrees as the top.

0
source

Source: https://habr.com/ru/post/1234850/


All Articles