objective-c - UIBezierPath containsPoint : don't work correctly?(更新: touch location in superview how to handle?)

标签 objective-c ios uibezierpath

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

这是一些代码:

在主视图 Controller 中:

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

在绘图 View 触摸结束时我这样做:

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

为什么它不起作用,难道 View 有另一个起源然后 self.view ?我该如何修复它?

编辑:

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

如果我更改 UIView 中的触摸方法: startPoint = [touch locationInView:self];到此startPoint = [touch locationInView:self.superview];然后它会正确读取触摸,但我的路径不会绘制。问题仍然只是底部 uiview 。那么我该如何更改,以便它返回一条在 super View 中触摸位置的路径,但在它自己内部绘制它?

最佳答案

查看文档:

A point is not considered to be enclosed by the path if it is inside an open subpath,   
regardless of whether that area would be painted during a fill operation. Therefore, to
determine mouse hits on open paths, you must create a copy of the path object and  
explicitly close any subpaths (using the closePath method) before calling this method.

我的猜测是您打开了一个子路径,因此 containsPoint 返回 NO。

关于objective-c - UIBezierPath containsPoint : don't work correctly?(更新: touch location in superview how to handle?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13787971/

相关文章:

iOS-WatchKit 文件传输工作不可靠

objective-c - NSOutlineView+NSTreeNode : where's my custom data gone?

ios - 在 iPhone 5 上如何阻止自动布局拉伸(stretch)弹出框的高度?

ios - 在 Storyboard 中为 TableView 实现一个事件指示器

iphone - UI贝塞尔路径 : Incorrect retrieval of view screenshot

ios - 使用 CALayers 绘制自定义形状和动画自定义属性?

ios - 用 UIBezierPath 画一条线

iphone - 如何在 iOS 7 中更改键盘的背景颜色

ios - 类方法+setLoggingEnabled : not found

ios - 为什么找不到崩溃日志