Easiest way to dismiss a dropdown menu

Hi guys,

my app has some dropdown menus and I want them to transitions back to their original (non visible) location when the user taps anything but the dropdown menu (background, other button, textfield,…). I got this working by adding eventlisteners to all the objects other than the dropdown menu. But this seems like a lot of repeated code for something that looks so simple. How would you guys approach a situation like this?

Kind regards,

Bram

You could just create a invisible rect on the scene but below the menu. And add a touch event to that rect that triggers menu to go away

Hi Scott, that was my first thought. But the touches weren’t received because of the alpha.

But I guess I gave up to quick, I should’ve just added 

button.isHitTestable = true

Thanks Scott!

I do what Scott said, but  use a newImageRect() with a transparent image.  

i.e. I leave the alpha at 100%, but the image itself is just a 16x16 transparent PNG stretched out to cover the whole screen.  

This goes below the object I want to have catch touches.  Then, if the user touches off my ‘desired’ object, the touch listener on my touch catcher activates and does whatever I want it to (block touches to underlying objects; close dialog, close drop down; etc.)

Any specific reason why you don’t use a rectangle created in Corona instead of an image?

You could just create a invisible rect on the scene but below the menu. And add a touch event to that rect that triggers menu to go away

Hi Scott, that was my first thought. But the touches weren’t received because of the alpha.

But I guess I gave up to quick, I should’ve just added 

button.isHitTestable = true

Thanks Scott!

I do what Scott said, but  use a newImageRect() with a transparent image.  

i.e. I leave the alpha at 100%, but the image itself is just a 16x16 transparent PNG stretched out to cover the whole screen.  

This goes below the object I want to have catch touches.  Then, if the user touches off my ‘desired’ object, the touch listener on my touch catcher activates and does whatever I want it to (block touches to underlying objects; close dialog, close drop down; etc.)

Any specific reason why you don’t use a rectangle created in Corona instead of an image?