Search code examples
iosobjective-cdrawinguibezierpathcashapelayer

completely erasing UIBezierPath & CAShapeLayer drawn items


In portrait mode (first time drawing)

enter image description here

After rotating to landscape, why are the older shapes:

enter image description here

I am using UIBezierPath & CAShapeLayer to draw circles & lines in a custom UIView's layer. The problem is inspite of being able to draw new circles & lines successfully after device is rotated, I am unable to remove the older drawn shapes. The new shapes drawn after device rotation are perfect, I just need to remove from screen those older shapes sticking in the screen. Images attached.


Solution

  • You can either remove the previous CAShapeLayer (with removeFromSuperlayer) or replace the path of the previous CAShapeLayer. You would appear to be adding a new layer without removing the old one, but of course it is impossible to tell without source code.