4
我目前正在开发应用程序,如“kresta应用程序”。首先,我从照片库挑选图像。接下来我的工作是用户可以选择他想要应用盲区和阴影的区域。所以我想要做的是我有四个引脚,用户可以触摸并拖动区域选择的引脚。我用下面的代码实现了这个逻辑。如何绘制不规则形状的矩形和填充ios中的四个针点的颜色
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];
我的问题是,在每次它,它添加一个图层。我如何实现这个逻辑?有什么办法可以删除上一层并更新新图层?或者我的方式是错误的,如果错误,请建议任何其他方式来实现这一逻辑。
是我的方法是否正确? – banu
@banu您的方式对于图层的初始添加是正确的,但对于后续更新,您只需更新路径,不要创建新的“CAShapeLayer”。我没有看到你指定填充颜色的位置(例如'square.fillColor = [[UIColor colorWithRed:1.0 green:1.0 blue:0.0 alpha:0.2] CGColor];'或者其他)。 – Rob
是的,我忘了它。我会添加它。谢谢罗布 – banu