UIBezierPath containsPoint: 不能正常工作?(更新:超视图中的触摸位置如何处理?) [英] UIBezierPath containsPoint: don't work correctly?(Updated: touch location in superview how to handle?)

查看:53
本文介绍了UIBezierPath containsPoint: 不能正常工作?(更新:超视图中的触摸位置如何处理?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有 2 个 UIViews 女巫可以绘制贝塞尔路径然后返回路径.然后我需要检查路径是否包含一个点,我在 [path containsPoint:currentObject.position] 的帮助下执行此操作,并且它适用于一个视图,但不适用于另一个视图.一个视图位于 iPhone 的上半部分,另一个视图位于下半部分.底部的那个不起作用.我尝试切换视图,然后还是同样的问题,最下面的不起作用.

So I have 2 UIViews witch can draw a bezierpath and then returns the path. Then I need to check if the path contains a point I do this with help of [path containsPoint:currentObject.position]and it works for one of the views but not the other. One view is on the top half of the iPhone and the other view is on the bottom half. The one on the bottom don't work. I tried to switch the views, and then it was the same problem, the bottom one doesn't work.

这是一些代码:

在主视图控制器中:

-(void)didEndPath:(UIBezierPath *)path DrawView:(DrawView *)draw {
    if ([path containsPoint:currentObject.position]) {
        //do stuff
    }
}

在 drawview touches 结束时,我这样做:

and in drawview touches ended I do this:

[self.delegate didEndPath:currentPath DrawView:self];

为什么不起作用,难道视图有另一个来源然后self.view?我该如何解决?

Why doesn't it work, can it be that the view has another origin then self.view? How do I fix it?

好的,所以我找到了问题,但没有找到解决方案.

Okey, so I found the problem but not the solution.

如果我从此更改 UIView 中的触摸方法:startPoint = [touch locationInView:self];到这个 startPoint = [touch locationInView:self.superview];然后它正确读取触摸但我的路径不会绘制.问题仍然只是底部的uiview.那么我该如何改变,让它在超级视图中返回一个带有触摸位置的路径,但在它自己内部绘制它?

If I change the touch methods in my UIView from this: startPoint = [touch locationInView:self];to this startPoint = [touch locationInView:self.superview];then it reads the touches correctly but my path won't draw. Still the problem is only with the bottom uiview. So how can I change so it returns a path with touches location in superview, but draws it within it self?

推荐答案

我通过创建 2 个路径解决了这个问题.一个有来自超级视图的点,一个没有.它有效,但我不知道它是否是最佳解决方案.

I solved the problem by making 2 paths. One with points from superview and one without. It works but i don't know if its the best solution.

这篇关于UIBezierPath containsPoint: 不能正常工作?(更新:超视图中的触摸位置如何处理?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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