I need something like that:
An image map (I think it will have to be done with anUIView
of some sort开发者_如何学Go) which is an image (a special map) with some areas (polygons) which should call an event when touched... How to make a poligon-"overlay" for images which fire an event?
The image map mentioned above and an UITableView
in a UIScrollView
- but I think this shouldn't be that hard...? Should look like this afterwards.
-------------------------- UIScrollView top
+-----------------------+
+ polygon UIView +
+-----------------------+
+-----------------------+
+ UITableView +
+-----------------------+
-------------------------- UIScrollView bottom
Thanks in advance for your answers!
I'd create a subclass of UIView (e.g. DOMImageMapView
), with a list of CGPathRef
or UIBezierPath
instances associated with it.
In DOMImageMapView
's drawRect:
implementation, you would draw the image, and then iterate through each path instance and fill it using CGContextFillPath()
or -[UIBezierPath fill]
.
For hit tests, you would implement touchesEnded:withEvent:
(or similar), and test each path via CGPathContainsPoint()
or -[UIBezierPath containsPoint:]
. If one of the paths returns YES
, call a delegate method like imageMapView:didSelectArea:
.
Your UITableViewController
(or UIViewController
with a UITableView
in it) would create the DOMImageMapView
and set itself as the delegate
. When an area is tapped, the controller will receive the callback and can handle the event appropriately.
精彩评论