I am freehand drawing a UIBezierPath but now I want to be able to erase the lines I previously drawn. Does anyone have any suggestions on how to do that?
@objc private func didPanWhiteboard(_ gesture: UIPanGestureRecognizer) {
let location = gesture.location(in: drawCanvasView)
switch gesture.state {
case .began:
path = UIBezierPath()
path.move(to: location)
strokeLayer = CAShapeLayer()
drawCanvasView.layer.addSublayer(strokeLayer)
path.stroke(with: shouldErase ? .clear : .normal, alpha: 1.0)
strokeLayer.strokeColor = toolColor.cgColor
strokeLayer.fillColor = UIColor.clear.cgColor
strokeLayer.lineWidth = toolWidth
strokeLayer.path = path?.cgPath
case .changed:
path.addLine(to: location)
strokeLayer.path = path.cgPath
case .cancelled, .ended: drawLayers.append(strokeLayer)
default: break
}
}
this is how I draw the lines and so far for erasing I tried:
path.stroke(with: shouldErase ? .clear : .normal, alpha: 1.0)
but it dosen't seem to do anything when shouldErase is true.
EDIT: this is what I'd like to achieve:
https://i.stack.imgur.com/gMXsE.jpg
Feel free to suggest any kind of approach.