我有一个UIView,作为子视图添加到我的视图控制器中。我在那个视图上绘制了一条贝塞尔曲线路径。下面是我的drawRect实现:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
UIBezierPath *bpath = [UIBezierPath bezierPath];
[bpath moveToPoint:CGPointMake(50, 50)];
[bpath addLineToPoint:CGPointMake(100, 50)];
[bpath addLineToPoint:CGPointMake(100, 100)];
[bpath addLineToPoint:CGPointMake(50, 100)];
[bpath closePath];
CGContextAddPath(context, bpath.CGPath);
CGContextSetStrokeColorWithColor(context,[UIColor blackColor].CGColor);
CGContextSetLineWidth(context, 2.5);
CGContextStrokePath(context);
UIColor *fillColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.5 alpha:0.7];
[fillColor setFill];
[bpath fill];
}
我希望检测此贝塞尔路径内的轻拍,但不包括位于UIView内且在路径外部的点。例如,在此情况下,如果我的触摸坐标是(10,10),则不应检测到它。我知道CGContextPathContainsPoint,但当触摸在路径内时它并没有帮助。有没有一种方法可以检测贝塞尔路径内的触摸事件?
CGPathCloseSubpath
。我已经更新了我的答案,请查看。 - Avt