Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView hidden property...is there more to it?

Coming from ActionScript, I would set Sprites to visible=false in order to keep them from being calculated in things like layout, and to ensure they would not respond to events.

In iOS development, I am continuing with this--if a UIView is not needed, I may both animate its alpha to zero and then set hidden=true. I wanted to know if I was wasting my time, or if there is a benefit to this. In my current project, I'm doing so with UIImageViews which are not responding to events anyway.

Is setting hidden to true good practice, or or just additional overhead?

like image 460
akaru Avatar asked Feb 17 '11 01:02

akaru


2 Answers

This is the best choice, because setting hidden to true removes view from the render loop. While setting alpha to 0 just makes view transparent.

like image 106
Max Avatar answered Oct 07 '22 08:10

Max


If you don't need it any more, then you should properly remove it from memory. In that case you would just animate its alpha (to make it look good), then dealloc it.

if you autoreleased it, then all you have to do is remove it from the superview and its retain will hit 0 and be dealloced.

[UIView animateWithDuration:.5
                 animations: ^ {
                      [myView setAlpha:0];
                 }
                 completion: ^ (BOOL finished) {
                      [myView removeFromSuperview];
                 }];
like image 26
ColdLogic Avatar answered Oct 07 '22 10:10

ColdLogic