I’m working on an app that lets the user stack graphics on top of each other.
The graphics are instantiated as a UIImageView, and is transparent outside of the actual graphic. I’m also using pan gestures to let the user drag them around the screen.
So when you have a bunch of graphics of different sizes and shapes on top of one another, you may have the illusion that you are touching a sub-indexed view, but you’re actually touching the top one because some transparent part of it its hovering over your touch point.
I was wondering if anyone had ideas on how we could accomplish ONLY listening to the pan gesture on the solid part of the imageview. Or something that would tighten up the user experience so that whatever they touched was what they select. Thanks
Create your own subclass of
UIImageView. In your subclass, override thepointInside:withEvent:method to return NO if the point is in a transparent part of the image.Of course, you need to determine if a point is in a transparent part. 🙂
If you happen to have a
CGPathorUIBezierPaththat outlines the opaque parts of your image, you can do it easily usingCGPathContainsPointor-[UIBezierPath containsPoint:].If you don’t have a handy path, you will have to examine the image’s pixel data. There are many answers on stackoverflow.com already that explain how to do that. Search for
get pixel CGImageorget pixel UIImage.