如何检查触摸点是否在UIBezierPath(iOS)上

我怎么知道一个触摸点(touchesBegan)是否在隐藏的UIBezierPath上?

[bezierPath containsPoint:touchPoint]; 

只要确保您的触摸点与bezierPaths点在同一个坐标系中,并且这些点在相同的上下文中,即在屏幕空间中。

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint touchPoint = [touch locationInView:self.view]; if ([self.bezierPath containsPoint:touchPoint]) { // do stuff } } 

另外请注意:如果您在某些CoreGraphics绘图中使用您的UIBezierPath,您将需要翻转touchPoint上的y轴…

touchPoint.y = self.view.bounds.size.height – touchPoint.y;