我正在用Swift 3.0实现一个着色应用程序,它使用UIBezierPath的触摸来填充着色样式。在touchesBegan中,我创建了路径:
touchFillPath = UIBezierPath()在touchesMoved中,我为每个新的点描边:
touchFillPath.addLine(to: location)
touchFillPath.stroke()但这会导致路径在同一区域上方多次描边,因此所选的颜色不透明度会发生变化。
我需要为每个touchesMoved调用绘制路径,以允许用户在移动触摸时看到着色的区域。
如何在不多次覆盖同一区域的情况下多次描边相同的路径?
发布于 2017-03-13 21:16:40
@joeybladb我已经尝试过你的解决方案,但它为每个“touchesMoved”操作绘制了很小的片段。
因此,为了解决这个问题,我将所有接触到的点保存在一个数组中:
pathPoints.append(NSValue(cgPoint:location))在调用touchFillPath.removeAllPoints()之后,我将所有这些点再次添加到路径中:
for (index, element) in (pathPoints.enumerated())! {
let point = element.cgPointValue
if index == 0 {
touchFillPath.move(to: point)
} else {
touchFillPath.addLine(to: point)
}
}所以下一次我调用touchFillPath.stroke()时,它会遍历整个路径:
touchFillPath.move(to: lastPoint)
touchFillPath.addLine(to: location)
touchFillPath.stroke()发布于 2017-03-05 21:28:52
在touchFillPath.stroke()之后,您将需要重置路径:
touchFillPath.removeAllPoints()
touchFillPath.move(to: location)https://stackoverflow.com/questions/42608137
复制相似问题