我目前正在开发像“kresta app”这样的应用程序。首先我从照片库中挑选图像。接下来我的工作是用户可以选择他想要应用百叶窗和阴影的区域。所以我想要做的是我有四个引脚,用户可以触摸和拖动引脚以进行区域选择。我用下面的代码实现了这个逻辑。
jpg
在触摸中我调用了这个方法
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];
我的问题是每次它添加一个图层。我如何实现这个逻辑?有什么方法可以删除前一层并更新新层?或者我的方式是错误的,如果错误,请提出任何其他方式来实现这个逻辑。