Search code examples
ioscocoa-touchuitouch

Detect touch coordinates on a sinle UIImageview


I have a single imageview with a static country map divided into regions of that country. What I'd like to do is detect the touch location on the image and provide content about the corresponding region. Since region borders are not linear, how can I save each region's area? Do I need several imageviews (or even custom UIButtons with those images) each belonging to one region or is it possible the way I'd like?

This is the first thing that came to my mind so maybe there is a simpler and better way which I'd love to hear about and I couldn't know how to search for this so apologies if there is a duplicate. And of course I'd appreciate the help.

Thanks


Solution

  • One simple & exact way would be to use Ole Begemann's OBShapedButtons - one for each state.

    This will allow you to detect exactly which state was selected. Simply put image of each state in separate buttons (with transparent surroundings) and align buttons next to eachother so that state-borders allign one to another.

    Buttons will detect the location of the press and if one button was pressed on its transparent region the touch will be passed along until the correct button gets it.