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

孤街醉人 提交于 2019-11-28 00:59:40

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/10831370/how-to-check-if-touch-point-is-on-uibezierpath-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!