【发布时间】:2014-03-27 15:16:15
【问题描述】:
我有一个 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。我已经更新了我的答案。请检查。 -
"检测此贝塞尔路径内的点击而不是 UIView 内的"此贝塞尔路径是在 UIView 内绘制的,那么如何点击在其中而不在 UIView 内?
-
@matt:编辑问题
-
@blancos - 谢谢,只要确保我们都在同一个页面上! :)
标签: ios objective-c core-graphics uibezierpath