Reputation: 2146
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.
Upvotes: 1
Views: 164
Reputation: 3591
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 :)
Upvotes: 3
Reputation: 15247
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 UIView
s, but this is probably not what you want.
Upvotes: 0