0

Just a question for general practice.

What is the difference between setting objects to .hidden = true and setting .alpha = 0?

Which is more efficient?

Plus if I have multiple objects on a view, should I just hide the view? Or hide the view and each object individually?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
james
  • 353
  • 3
  • 16
  • 2
    Possible duplicate of [what's the difference between view's hidden = yes and alpha = 0.0f](http://stackoverflow.com/questions/10911696/whats-the-difference-between-views-hidden-yes-and-alpha-0-0f) – Bista Sep 14 '16 at 14:57
  • @Mr.UB Thanks, but about the other part of my question regarding a view that contains UI objects. Should I only hide the view or all the objects? For I am trying to maximise efficiency. – james Sep 14 '16 at 14:59
  • It is mentioned- "_However using hidden to actually hide a view not only in a graphical sense but also from ui events might result in a more efficient responder chain when you have lots of nested views._" – Bista Sep 14 '16 at 15:01

3 Answers3

1

1) .hidden is more efficient, because it is more than graphical, it removes the UI events thus resulting in a more efficient responder

2) Hidden the container view only is more efficient, tahtn doing that and looping through its elements too and it will have the same behavior.

Franklin Rivero
  • 581
  • 1
  • 3
  • 18
1

If you set a view to "hidden", the OS will not even try to draw it or any subviews. The drawing code for a view is roughly

if (! hidden) {
    for (view* subview in views)
        if (! subview.hidden)
            subview.draw;
    [self drawmyself];
}

So this is much quicker than setting alpha, because the graphics subsystem would have to look for that exception value alpha = 0, and probably will look at the subviews anyway.

The same goes for the responder chain, "hidden" views are not looked at at all. And hidden is much easier to handle: If you set alpha, you must remember the previous alpha value so you can restore it, or you need complicated code to calculate the new alpha value in all the places where you might want to show the view again.

gnasher729
  • 51,477
  • 5
  • 75
  • 98
0

Actually there is no different from "alpha = 0" and "hidden = true".

If you just set anyone of them(alpha=0 or hidden=true), the view and the view's subviews will disappear and they will also do not response any event.

Maybe there is some different in efficient, but believe me you can not feel it.

Alanc Liu
  • 1,294
  • 10
  • 15