I have a 3D map with many different shaped buildings. I would like users to click a building on the map, which would act as a segue to a new view.
I planned to go about this by creating invisible buttons the same shapes as the buildings, and then laying them on top of the imageview (which holds the map).
After doing some reading I found that it isn’t as simple as I thought to create custom buttons (I think that I will have to do a lot of sublcassing and customization, which doesn’t seem reasonable when I have 50+ different shaped buttons to make), so I was wondering if there was another aproach I could use to solve this problem.
Edit: I should add that right now that all functionality is working, but I am having to use default rectangular buttons, with alpha set to 0.1.
EDITED TO IMPROVE DATAMODEL
To do this you will have a UIView with your map image in the background. You can do this with either a UIImageView or by rendering the image yourself in drawRect.
You will then define several CGPath references. One for each building by doing something like this… How to create CGPathRef from Array of points The points will be the corners of each building.
Now store these paths in an array somehow. You will need one path for every “clickable”
building.
I would store the paths inside a Building object or something…
Now in the UIView subclass you override
- (void)touchesBegan.... You can then get the touch point and iterate through your paths to find which one is touched…