1

I am writing a small iPad application that draws a shape from a list of coordinates. I would like to tap anywhere inside the shape and have some action occur (i.e. NSLog proving it worked).

Does anyone know how to create a tappable area that is defined by a list of coordinates?

The shape is being drawn on top of a MKMapView.

4

2 回答 2

3

我的方法是:

让标记形状的点位于 UIView 的子类中。为该类覆盖 pointInside:withEvent:。然后看看如何确定二维点是否在多边形内?并使用您的新知识来实现​​ pointInside:withEvent:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 
{
    //Left as homework
}

您可以使用常规的点击手势识别器:)

于 2013-03-25T16:30:45.037 回答
0

只有 的 实例是UIView可点击的,它们的区域由它们的 rectangle 属性定义frame。原则上,可以(对于非常简单和特定的形状)用多个UIViews 来近似由坐标定义的区域,但这可能不是您想要的。

于 2013-03-25T16:17:33.113 回答