我有一个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
“检测不在UIView内部的这个贝塞尔路径中的tap”这个贝塞尔路径是在UIView内部绘制的,所以如何在它内部但不在UIView内部的水龙头? – matt
@matt:编辑问题 – blancos