可能重复:
如何检查用户是否在CGPath附近轻敲?
我正在从这里关注Apple的指南
尝试仅在我的UIBezierPath的描边部分检测触摸事件.如果我使用UIBezierPath方法containsPoint,它工作正常,但它检测笔划和UIBezierPath的填充部分上的触摸事件,我希望它只发生在描边部分.
按照Apple的指南(在链接的清单3-6),我创建了这个功能:
- (BOOL)containsPoint:(CGPoint)point onPath:(UIBezierPath*)path inFillArea:(BOOL)inFill
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGPathRef cgPath = path.CGPath;
BOOL isHit = NO;
// Determine the drawing mode to use. Default to
// detecting hits on the stroked portion of the path.
CGPathDrawingMode mode = kCGPathStroke;
if (inFill)
{
// Look for hits in the fill area of the path instead.
if (path.usesEvenOddFillRule)
mode = kCGPathEOFill;
else
mode = kCGPathFill;
}
// Save the graphics state so that the path …Run Code Online (Sandbox Code Playgroud)