如何检查触摸点是否在UIBezierPath(iOS)上 [英] How to check if touch point is on UIBezierPath (iOS)

查看:416
本文介绍了如何检查触摸点是否在UIBezierPath(iOS)上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么知道触摸点(touchesBegan)是否在隐藏的UIBezierPath上?

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

推荐答案

[bezierPath containsPoint:touchPoint];

只需确保您的触摸点与bezierPaths点位于同一坐标系中并确保点数在屏幕空间中都在相同的上下文中。

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
    }
}

另请注意:如果您在某些CoreGraphics绘图中使用UIBezierPath,则需要在touchPoint上翻转y轴,例如......

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;

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

这篇关于如何检查触摸点是否在UIBezierPath(iOS)上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆