我们遇到了这样的问题。为了解决这个问题,我们在 Adobe Illustrator 中创建了一个黑白蒙版。您需要对您想要的每个不同区域执行此操作。
接下来,我们导出该文件。我不记得文件导出选项,但基本上你会得到一个文本文件,其中包含大量路径数据,其中包括直线、贝塞尔曲线等。
然后我们获取这个文件并编写一个导入器来解析它并创建一个 CGPath。
最后阶段是比较简单的阶段。您从 UITouch 获取触摸点并执行 CGPathContainsPoint 调用。
这是一些伪代码:
跳过队伍,直到到达带有“1 XR”的那一个。这就是
指示后续行中有意义的内容。
使用分隔符“”将行拆分为组件数组。
该行的最后一个组成部分是动作。如果是“m”,则表示路径移动;如果是“C”,则表示贝塞尔曲线;如果是“L”,则表示直线。
如果它是“Y”或“V”,那么您需要获取上一行的组件并解析如下:
(a) 组件数量包括动作,因此我们需要减少它。例如。 274.5600 463.6800 米
(b) 如果这条线有四个坐标,而前一条线有两个坐标,那么它是一个点节点到贝塞尔曲线节点。按如下方式计算贝塞尔曲线点:
cp1x = previous line's components object at index 0
cp1y = previous line's components object at index 1
cp2x = this line's components object at index 0
cp2y = this line's components object at index 1
x = this line's components object at index 2
y = this line's components object at index 3
(c) 否则,如果这一行有四个坐标,而上一行有四个或六个坐标,则如下图:
cp1x = this line's components object at index 0
cp1y = this line's components object at index 1
cp2x = this line's components object at index 2
cp2y = this line's components object at index 3
x = this line's components object at index 2
y = this line's components object at index 3
其中 cp 是“控制点”。因此,您有控制点一和控制点二及其各自的 x 和 y 坐标。