Question

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.

Was it helpful?

Solution

My approach would be:

Have the points that demark the shape live within a subclass of UIView. Override pointInside:withEvent: for that class. Then look at How can I determine whether a 2D Point is within a Polygon? and use your new knowledge to implement pointInside:withEvent:

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

You can use a regular tap gesture recognizer with this :)

OTHER TIPS

Only instances of UIView are tappable, and their area is defined by their rectangular property frame. In principle it would be possible (for very simple and specific shapes) to approximate the area defined by coordinates by multiple UIViews, but this is probably not what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top