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

How can I find out if a touch point (touchBegan) is on a hidden UIBezierPath?

+6
source share
1 answer
[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 in the same context, that is, on the screen.

 - (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 use your UIBezierPath in some CoreGraphics drawing, you will need to flip the y axis to touchPoint, for example ...

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

+10
source

Source: https://habr.com/ru/post/917086/


All Articles