我目前正在开发类似“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];
我的问题是每次它都添加一层。我如何实现这个逻辑?有什么方法可以删除上一层并更新新层?或者我的方法是错误的,如果错误请建议任何其他方法来实现这个逻辑。
最佳答案
如果你在类属性中保存对这个 CAShapeLayer
的引用,你可以简单地一次又一次地更新它的 path
属性,它会自动更新子层你的 View 层。所以,addSublayer
一次,然后在将来,只要你想反射(reflect)覆盖你的形状的变化,就更新这个 CAShapeLayer
的 path
屏幕上的图像。
关于iphone - 如何在ios中绘制不规则形状的矩形并用四个针点填充颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18094608/