我目前正在开发类似于“kresta app”的应用程序。首先我从相册中选择了图片,然后用户可以选择他想要在哪个区域应用百叶窗和遮阳帘。所以我想做的是有四个固定点,用户可以触摸并拖动这些点来选择区域。我使用以下代码实现了这个逻辑。
在“touches moved”方法中,我调用了这个方法。
在“touches moved”方法中,我调用了这个方法。
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];
我的问题是每次都添加一个图层。我该如何实现这个逻辑?有没有办法删除之前的图层并更新新的图层?如果我的方法不正确,请建议其他实现此逻辑的方法。
CAShapeLayer
。我也没有看到你指定填充颜色的地方(例如square.fillColor = [[UIColor colorWithRed:1.0 green:1.0 blue:0.0 alpha:0.2] CGColor];
或其他),请注意。 - Rob