-1

This is my coding to draw a line using CAShapeLayer .no i like to remove the CAShapeLayer along user drag.

UIBezierPath *path = [UIBezierPath bezierPath];
                [path moveToPoint:CGPointMake(touchPoint.x,touchPoint.y)];
                [path addLineToPoint:CGPointMake(startingPoint.x,startingPoint.y)];

                shapeLayer = [CAShapeLayer layer];
                shapeLayer.lineCap=kCALineCapSquare;
                shapeLayer.path = [path CGPath];
                shapeLayer.lineWidth = single.width;
                shapeLayer.fillColor = [[UIColor redColor] CGColor];
                [self.layer addSublayer:shapeLayer];
                [clearBeizer addObject:shapeLayer];

This is screenshot of my expectation:

this is user touched places

now i like to remove the cashapelayer along user touch like this

enter image description here

Kishore kumar
  • 143
  • 1
  • 14
  • Possible duplicate of [How to remove CAShapeLayer along user drag?](http://stackoverflow.com/questions/35053624/how-to-remove-cashapelayer-along-user-drag) – Hamish Feb 03 '16 at 15:30
  • please don't post multiple questions for the same problem, update the original question with the images and updated code. – Hamish Feb 03 '16 at 15:31

1 Answers1

1

There is no straight way to achieve this. You can try the following ways:

  1. Instead of removing the CAShapeLayer which is created by a bezier-path, you are looking for a way to remove the bezier-path at touch point. One way is to store the bezier points in an array, and compare the touch point to the points in an array and remove the point and redraw the whole bezier-path with the remaining points.

  2. Instead of removing the bezier path, I suggest you to draw a new bezier path with the custom image/path which is having an color similar to the background color of your view, and draw it on the CAShapeLayer, so that the bezier path get covered by the new bezier path.

Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109