Completely erases UIBezierPath and CAShapeLayer elements

In portrait mode (first time)

enter image description here

After turning to the landscape, why are the old forms:

enter image description here

I use UIBezierPath and CAShapeLayer to draw circles and lines in a custom UIView layer. The problem is that we can successfully create new circles and lines after turning the device, I can’t delete the old shapes. The new shapes created after rotating the device are perfect, I just need to remove from the screen those old shapes that stick together on the screen. Images are attached.

+6
source share
2 answers

You can remove the previous CAShapeLayer (using removeFromSuperlayer ) or replace the path previous CAShapeLayer . It seems you are adding a new layer without deleting the old one, but of course it is impossible to say without source code.

+9
source

aah! found a solution using rootView.layer.sublayers = nil removed all previous forms

+3
source

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


All Articles