4

我目前正在开发像“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];

我的问题是每次它添加一个图层。我如何实现这个逻辑?有什么方法可以删除前一层并更新新层?或者我的方式是错误的,如果错误,请提出任何其他方式来实现这个逻辑。

4

1 回答 1

1

CAShapeLayer如果您在类属性中保存对此的引用,则可以简单地path一次又一次地更新其属性,它会自动更新视图层上的子层。因此,addSublayer一次,然后在将来,只要您想在屏幕上反映覆盖图像的形状的变化,就可以随时path更新。CAShapeLayer

于 2013-08-07T04:40:30.787 回答