【发布时间】:2013-08-07 04:47:51
【问题描述】:
我无法在使用 UIBezierpath 绘制的线条中找到接触点。 CGPathContainPoint 不适用于线路。请帮帮我
【问题讨论】:
标签: ios uibezierpath cashapelayer
我无法在使用 UIBezierpath 绘制的线条中找到接触点。 CGPathContainPoint 不适用于线路。请帮帮我
【问题讨论】:
标签: ios uibezierpath cashapelayer
您可以创建另一个路径对象来表示路径在屏幕上的实际外观,然后检查触摸点是否在该路径内。在CGPath reference 中,您会找到方便的构造函数CGPathCreateCopyByStrokingPath。你会像这样使用它:
CGPathRef originalPath = myBezierPath.CGPath; //The single-line path
//Use the values you use to draw the path onscreen,
//or use a width representing how far the user can touch
//for it to be recognized by the path.
//For example, for an error tolerance of 4px, use a width of 8px.
CGPathRef strokedPath = CGPathCreateCopyByStrokingPath(originalPath, NULL, lineWidth, lineCap, lineJoin, miterLimit);
BOOL pathContainsPoint = CGPathContainsPoint(strokedPath, NULL, touchPoint, NO);
如上所示,这让您可以指定一个区域让用户触摸而不是一条线。
希望这会有所帮助!
【讨论】: