iPhone,地图,可点击的非矩形区域 [英] iPhone, Map, Clickable non-rectangular areas

查看:142
本文介绍了iPhone,地图,可点击的非矩形区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人对如何在iPhone上实现以下内容有任何想法?我们有一张美国地图,它有不同的区域(气候区域,我相信),颜色不同。它们不是矩形的,不遵循州或邮政编码或县或任何其他定义的行。所以,我们的区域非常圆,甚至不一定是连续的。

Anyone have any ideas on how I could implement the following on the iPhone? We have a map of the US, and it has different regions (climate regions, I believe) that are different colors. They are not rectangular, and don't follow state or zip or county or any other defined lines. So, our areas a very round-y and not even necessarily contiguous.

我愿意让我们的用户能够点击他们的区域,我将能够告诉他们从哪里触及它所在的区域,但对于我的生活,如果没有制作许多很多矩形以便最好地适应曲线,我无法弄清楚如何做到这一点。

I would LOVE to give our users the ability to click on their region and I would be able to tell from where they touched what region it was, but for the life of me, short of making many many many rectangles to do a best fit on the curves, I can't figure out how to do this.

任何想法?

编辑:这些地区可能就像这样...... 链接文字

The regions could be as hard as this... link text

推荐答案

这些地区是如何定义的?如果您可以获取点数据,则使用以下命令创建CGPath:

How are these regions defined? If you can get the point data, then create a CGPath using:

CGPathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path,null,xpoints[0],ypoints[0])
for (int i = 1; i < numpoints; ++i) {
  CGPathAddLineToPoint(path,null,xpoints[i],ypoints[i]);
}
CGPathCloseSubpath(path);

然后,当用户触摸时,对于每个区域,检查它是否包含触摸点:

Then whenever the user touches, for each region, check whether it contains the touch point:

if (CGPathContainsPoint(path,null,touchPoint,false)) ...

当你完成这些地区后别忘了发布:

And don't forget to release when you're done with the regions:

CGPathRelease(path);

请注意,您可以在一个CGPathRef中创建多个单独的子路径,并在检查时检查所有子路径遏制。

Note that you can create several separate subpaths in one CGPathRef and it will check all the subpaths when you check for containment.

如果你愿意,你可以尝试使用弧线或曲线来获得正确的线条,但这是我不太熟悉的东西。

If you want to, you can try using arcs or curves to get the lines right, but that's something I'm not too familiar with.

这篇关于iPhone,地图,可点击的非矩形区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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