How to check if touch point is on UIBezierPath (iO

2020-02-11 03:40发布

How could I know if a touch point (touchesBegan) is on a hidden UIBezierPath?

1条回答
劳资没心,怎么记你
2楼-- · 2020-02-11 04:29
[bezierPath containsPoint:touchPoint];

Just make sure that your touch point is in the same coordinate system as the bezierPaths points and that the points are within the same context i.e. both in screen space.

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

Also note: If you are using your UIBezierPath in some CoreGraphics drawing you will want to flip the y-axis on the touchPoint for example...

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

查看更多
登录 后发表回答