How to draw an irregular rectangle and fill the color with four dots in ios

I am currently developing an application like "kresta app". First of all, I selected an image from the photo gallery. Then, in my work, the user can choose in which area he wants to apply curtains and shadows. so I want to have four contacts, and the user can tap and drag the contacts to select the area. I implemented this logic using the code below.

enter image description here Jpg

In the affected movements, I called this method

UIBezierPath *aPath = [UIBezierPath bezierPath]; // Set the starting point of the shape. [aPath moveToPoint:pinImageView1.center]; // Draw the lines. [aPath addLineToPoint:pinImageView2.center]; [aPath addLineToPoint:pinImageView3.center]; [aPath addLineToPoint:pinImageView4.center]; [aPath closePath]; CAShapeLayer *square = [CAShapeLayer layer]; square.path = aPath.CGPath; [pickedImageView.layer addSublayer:square]; 

My problem is that every time she adds a layer. how to implement this logic? - any way to delete the previous layer and update a new layer? or my path is wrong, if wrong, suggest any other way to implement this logic.

+4
source share
1 answer

If you keep a reference to this CAShapeLayer in the class property, you can simply update its path property again and again, and it will automatically update the sublayer at your view level. So, addSublayer once, and then in the future just update the path for this CAShapeLayer anytime you want to reflect changes in the form that overlays your image on the screen.

+1
source

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


All Articles