Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if touch point is on UIBezierPath (iOS) [closed]

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

like image 901
headkit Avatar asked May 31 '12 10:05

headkit


1 Answers

[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;

like image 191
Chris Heyes Avatar answered Nov 03 '22 08:11

Chris Heyes