如何判断一个触点(touchesBegan)是否在隐藏的UIBezierPath上?
如何判断一个触点(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;