如何获得特定的触摸区域? [英] How to get particular touch Area?

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

问题描述

我是Iphone开发的新手,

I am new to Iphone Development,

给予以下地图。每当我选择一个特定的部分,如西澳大利亚,我想提出一个触摸事件。但是那个特定的区域不是正方形或圆形来提及触摸区域。边界不是有序的。如何获得触摸事件?

Given the following map. I want to raise a touch event whenever i select a particular part like "Western Australia". But that particular area is not square or circle to mention the touch area. The boundaries are not in order. How can i get that touch event?

请任何一位指导我或向我提供有关该部分工作的教程。

Please any one guide me or give me a tutorial how work with that part?

推荐答案

在链接地图中,您可以看到每个区域都是由多边形定义的,由顶点数组表示。 (如果你没有看到这个,那么看看html源,你会看到它。)你可以在互联网上找到很多讨论算法,可以确定一个点是否在这样描述的多边形内。 这里有一个值得一看的讨论,在你长度不够之前是非常彻底的),看看交叉计数算法一节。这是一个相当简单的方法相比,我看到的其他一些。

In your linked map, you can see that each region is defined by polygons, represented by an array of vertices. (If you don't see this, then look at the html source and you will see it then.) You can find a lot of discussion on the internet about algorithms that can determine if a point is inside a polygon described this way. Here is one discussion that may be worth looking at, and before you get to discouraged by it's length (it is very thorough), look at the section titled The "Crossing Count" Algorithm. It's a pretty simple method compared to some of the others that I have seen. It comes down to determining it lines intersect and counting how many edges of the polygon intersect with a ray.

你需要检查触摸的点对每个多边形,直到你找到一个多边形它在里面。可能值得的一件事是首先检查触摸点是否在边界框内,由每个多边形顶点数组的min x,max x,min y和max y值定义。

You need to check the touched point against every polygon until you find one that it is inside. One thing that might be worthwhile is to first check if the touch point is inside the bounding box, defined by the min x, max x, min y, and max y values of the each polygon vertex array. If it's not inside the bounding box, then it's not inside the polygon.

至于检测触摸事件及其位置,查看我对此问题的回答,其中介绍了如何确定屏幕,触摸发生(使用touch:locationInView:)。

As far as detecting the touch event and where it is, look at my answer to this question, which tells how to determine where on the screen that the touch occured (using touch:locationInView:).

我不知道你是否打算放大和缩小你的图片,并发症如何去做这个。如果这个响应不是很有帮助,你能提供更多的信息,你想做什么?

I don't know if you intend to zoom in and out of your images, but that will add some complications to how you go about this. If this response doesn't quite help, could you provide more info on what you are trying to do?

这篇关于如何获得特定的触摸区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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