Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Transparent ImageView / Button


I have some troubles with the ImageView for a program I am writing for iPhone : I have 2 ImageViews which overlap each other, both contain an image with some transparent parts (PNG).

When I click in the transparent part of the imageView (with the highest zIndex), the eventListener is called for this imageView. So the 'boundingBox' of the imageView is used to call the listener. I would like the call the listener only when a non-transparent part is clicked!

This way it becomes possible to click 'through' the imageView and possibly call the listener of the imageView with a lower zIndex…

Is this possible with Titanium ?

Thanks in advance!

— asked November 18th 2010 by Ruben Thys
  • bounding
  • box
  • event
  • eventlisteners
  • handling
  • imageview
  • imageviews
  • ios
  • iphone
  • transparency
  • transparent
  • zindex

1 Answer

  • Ruben

    There is no way provided inherently in the Ti (and possibly android/iphone) API that allows you to click through images, simply because a portion is transparent. Having said that, I think what you are intending to do may be technically possible but, from a practical POV, it would be pretty tricky to implement. Anyway, here are a couple of suggestions:

    The singletap event of an ImageView object exposes the x and y coordinates of where in the imageview the image was tapped. However, you would need to know exactly where the transparent areas exist in order to respond accordingly.

    Alternatively, you could split the image up into separate parts, create an imageview for each, and then position them on the screen so that they appear as a single, whole image. At the transparent parts of the image, no imageview would exist, and hence the imageview beneath it could receive the event unencumbered.

    So, technically it may be possible, but depending on the size of device and your application's purpose, you should bear in mind that a user's finger may not provide an accurate way of clicking a specific part of an image. Whether that is true or not is for you to decide for your specific situation.

    Hope this helps, anyway.

    — answered November 18th 2010 by Paul Dowsett
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.