Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

what's the difference between alpha=0 and hidden=YES?

snowffersnowffer Posts: 14Registered Users
edited November 2010 in iPhone SDK Development
Hello, everyone

I want to put a UIView as a subview to the toppest of all the other subviews. And I want to let this UIView be totally transparent and also let this UIView receive some input events such as slipping over its surface. So I set its alpha to Zero. It is totally transparent after that but the strange thing is it can't receive any input events. And if I tap it, the other UIViews below it would receive the tap event. It seems that the UIView whose alpha=0 disappears or hides. If that's true, I wonder that what's the difference between alpha=0 and hidden=YES?!!! How could it be?!! If alpha=0 and hidden=YES are the same, why do we need property hidden?

If anyone could give me an answer to this question or tell me another way to let a UIView be transparent and receive some input events at the same time, I'll appreciate him/her very much.

Also thank the guys who come in to read my question.

BTW, the UIView can receive events when its alpha value equals or more than 0.02. But I can't let it be 0.02 because of some reasons. I want it to be Zero.
Post edited by snowffer on

Replies

  • iPhoneConnectioniPhoneConnection Posts: 148Registered Users @ @
    edited November 2010
    You're assuming all controls have an alpha attribute. They don't.
    iPhoneConnection
    (57Digital Ltd - Mobile App Developers) | UK Apple Watch App Developers | Blog: UK iPhone Developers
  • Duncan CDuncan C Posts: 9,034Tutorial Authors, Registered Users @ @ @ @ @ @ @
    edited November 2010
    snowffer wrote: »
    Hello, everyone

    I want to put a UIView as a subview to the toppest of all the other subviews. And I want to let this UIView be totally transparent and also let this UIView receive some input events such as slipping over its surface. So I set its alpha to Zero. It is totally transparent after that but the strange thing is it can't receive any input events. And if I tap it, the other UIViews below it would receive the tap event. It seems that the UIView whose alpha=0 disappears or hides. If that's true, I wonder that what's the difference between alpha=0 and hidden=YES?!!! How could it be?!! If alpha=0 and hidden=YES are the same, why do we need property hidden?

    If anyone could give me an answer to this question or tell me another way to let a UIView be transparent and receive some input events at the same time, I'll appreciate him/her very much.

    Also thank the guys who come in to read my question.

    BTW, the UIView can receive events when its alpha value equals or more than 0.02. But I can't let it be 0.02 because of some reasons. I want it to be Zero.


    I believe that Cocoa Touch treats and alpha less than .02 as also being hidden, since below that alpha level it's invisible, and Apple's engineers decided that invisible controls should not be clickable.

    Using an alpha value requires that the graphics hardware blend each pixel from the object with everything underneath. It's compute-intensive. The hidden flag, on the other hand, is a switch. If you turn it on, the OS knows it doesn't have to draw the object at all.

    In order to do what you're trying to do you might have to leave the object's alpha value as 1, but set the alpha value of all of its pixels to zero. (Set it's background color to [UIColor clearColor] and don't give it any contents. That should enable it to receive events, but still be invisible.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
Sign In or Register to comment.