5

When I use CAShapeLayer and create a rectangle shape then the path starts at rectangle's origin (top-left corner) and draws clockwise. Now if I want to draw only part of the shape then I'm using strokeStart and strokeEnd properties. The problem comes when I want to draw a part consisting the path's end points. In this case the path is closed and it starts and ends on rectangle's top-left corner. When I'm setting strokeStart=0.8 and strokeEnd=0.2 I'm hoping it to draw the last section of the path and a bit from the beginning of the path. However, this is not working. Are there any ideas or tricks how to do this?

Update:

Adding an image to clarify what I mean above. I want an animation which draws a small amount of rectangle and that drawn part circles over the rectangle: enter image description here

frangulyan
  • 3,580
  • 4
  • 36
  • 64
  • A little difficult to follow. Might help if you post a picture of what you are describing. – Beau Nouvelle Oct 17 '15 at 11:23
  • Ah right I understand. Little tricky with a rectangle, but with a circle its a little easier since you can just rotate the circle and still start the stroke from 0.0. Does the answer here help at all? http://stackoverflow.com/questions/13333214/cabasicanimation-setting-start-stroke-position – Beau Nouvelle Oct 17 '15 at 12:50
  • I think so, in some scenarios I also have a circle, so good to know :) – frangulyan Oct 17 '15 at 15:51
  • Can you duplicate the layer and do 0->0.2 and 0.8 ->1 – leafcutter Feb 13 '20 at 14:05

1 Answers1

2

The short answer is that I don't think you can do that, at least not with a single path that will draw any of the segments in your examples. I'm pretty sure that strokeStart must be less than strokeEnd.

If you want to draw your last segment you'd need to create a custom rectangle path that started at the lower left corner and wrapped around.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • Alternately, you could apply a rotation transform to the layer and then adjust your start/end settings to compensate. – Duncan C Oct 18 '15 at 18:45