如何检测/处理弯曲区域的触摸事件? [英] How to detect/handle touch events on curved regions?

查看:98
本文介绍了如何检测/处理弯曲区域的触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用原生iPad应用程序(如果需要,我们可以假设iOS 4.3+),我需要有一系列相互碰撞的弯曲区域。

I'm starting on a native iPad app (we can assume iOS 4.3+ if necessary) where I need to have a series of curved regions that bump up against each other.

我喜欢一些关于处理这个问题的最佳方法的建议。

I'd love some advice about the best way to handle this.

有人认为我使用的是WebView,只有一个JPG和一个HTML图像映射,但我真的更喜欢使用某种支持的原生UI元素曲线。

One thought I had was to use a WebView and just have a JPG and an HTML image map but I'd really prefer to use some kind of native UI element that supports curves.

任何建议?

推荐答案

我们遇到了问题喜欢这个。为了解决这个问题,我们在Adobe Illustrator中创建了一个黑白面具。您需要为您想要的每个不同区域执行此操作。

We had a problem something like this. To resolve it, we created a black and white mask in Adobe Illustrator. You'll need to do this for each and every distinct region that you want.

接下来,我们导出了这个文件。我不记得文件导出选项,但基本上你得到一个文本文件,其中包含一些路径数据,包括行,bezier曲线等。

Next, we exported this file. I can't remember the file export option, but basically you get a text file that has a load of path data that includes lines, bezier curves, etc.

然后我们拿了这个文件并编写了一个解析它的导入器并创建了一个CGPath。

We then took this file and wrote an importer that parsed it and created a CGPath.

最后一个阶段很简单。你可以从UITouch获得你的触摸点并进行CGPathContainsPoint调用。

The final stage is the easy bit. You get your touch point from UITouch and do a CGPathContainsPoint call.

这里有一些伪代码:


  1. 在我们使用1 XR之前跳过线。这是后续行中有意义的
    指示。

  1. Skip lines until we get to one with "1 XR". That's the indication of something meaningful in the subsequent line.

使用分隔符将行拆分为组件数组。

Split the line into an array of components using a separator of " ".

该行的最后一个组成部分是行动。如果它是m则是路径移动,如果它是C,则它是一条bezier曲线,如果它是L则是一条线。

The last component of the line is the action. If it's "m" it's a path move, if it's "C", it's a bezier curve, and if it's "L" it's a line.

如果它是一个Y或V然后你需要得到前一行的组件并解析如下:

If it's a "Y" or a "V" then you need to get the previous line's components and parse as follows:

(a)组件数包括行动,因此我们需要减少这一点。例如。 274.5600 463.6800 m
(b)如果此行有四个坐标且前一个有两个坐标,则它是贝塞尔节点的点节点。计算贝塞尔曲线点如下:

(a) Component count includes action, so we need to reduce this. E.g. 274.5600 463.6800 m (b) If this line has four coordinates and the previous one has two, then it's a point node to a bezier node. Figure your bezier curve points as follows:

    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)否则,如果此行有四个坐标且前一行有四个或者六个坐标,如下所示:

(c) Otherwise if this line has four coordinates and the previous line has four or six coordinates, figure as follows:

    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是控制p oint。所以你有控制点1和控制点2及其各自的x和y坐标。

Where cp is "control point". So you have control point one and control point two with their respective x and y coordinates.

这篇关于如何检测/处理弯曲区域的触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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