用于点检测的宽贝塞尔路径

时间:2015-07-11 12:35:28

标签: ios uibezierpath

我有一条复杂的路径,有几个Bezier段连接在一起。此路径是动态的,用户可以在此路径中添加和删除点。

当我绘制路径时,我保存UIBezierPath副本,如下所示:

CGContextBeginPath(context);
for (NSUInteger i = 0; i < _points.count - 1; i++)
{
    // ...
    CGContextAddCurveToPoint(context, cp1x, cp1y, cp2x, cp2y, endX, endY);
}
_path = [UIBezierPath bezierPathWithCGPath:CGContextCopyPath(context)];
CGContextStrokePath(context);

我用长按手势创造新点:

- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer
{
    // ...
    CGPoint point = [recognizer locationInView:self];
    if ([_path containsPoint:point])
    {
        // process point
    }
    // ...
}

但这需要用户点击非常靠近路径。我希望在路径周围有更宽的区域,我认为任何水龙头都有效(如线宽)。

如何配置UIBezierPath以允许更广泛的区域?我希望它控制这个区域的宽度。

1 个答案:

答案 0 :(得分:0)

这是可能的解决方案:

@echo off

set "source=c:\users\microsoft\desktop\text.txt"
set "target=c:\users\microsoft\desktop\text2.txt"

setlocal EnableDelayedExpansion
(
    for /F "tokens=1* delims=:" %%a in ('findstr /N "^" %source%') do (
        set "line=%%b"
        if defined line set "line=!line:test=mytest!"
        echo(!line!
    )
) > !target!
Endlocal
del %source% & ren %target% text.txt
pause >nul

现在我们需要它:

CGPathRef pathCopy = CGContextCopyPath(context);
// 16 is the width of path where we want to have hit test
CGPathRef tapPath = CGPathCreateCopyByStrokingPath(pathCopy, NULL, 16, kCGLineCapButt, kCGLineJoinMiter, 0.6);
// this path will be used for hit test
_linePath = [UIBezierPath bezierPathWithCGPath:tapPath];
[_linePath closePath];