What is the impact of view.alpha = 0 vs view.hidden = YES? What is the impact of view.alpha = 0 vs view.hidden = YES? ios ios

What is the impact of view.alpha = 0 vs view.hidden = YES?


I am not sure that a view with alpha 0.0 is still drawn. Check the documentation library:

Hiding Views

To hide a view visually, you can either set its hidden property to YES or change its alpha property to 0.0. A hidden view does not receive touch events from the system. However, hidden views do participate in autoresizing and other layout operations associated with the view hierarchy. Thus, hiding a view is often a convenient alternative to removing views from your view hierarchy, especially if you plan to show the views again at some point soon.

I also have found this answer here http://www.iphonedevsdk.com/forum/iphone-sdk-development/65525-whats-difference-between-alpha-0-hidden-yes.html

That says:

I believe that Cocoa Touch treats and alpha less than 0.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.


Something with an alpha of zero, still is drawn, however a view that is hidden is not redrawn to the screen. Since this only happens when the view changes anyways, the difference should be insignificant. If you are experiencing performance issues, I would highly recommend profiling with the time profiler and core animation instruments.


One advantage of setting alpha instead of the hidden property is that the alpha property plays more nicely with animations. I had an animation to show/hide my navigation bar and when I used the alpha property the navigation bar faded away while the hidden property was more abrupt.