bas bas - 1 month ago 11x
iOS Question

Performance of UIView: removeFromSuperview VS hide

This question is really basic. What is the performance difference between removing a

from the view hierarchy and hiding a

I have read that Views that are not needed should be removed from the view hierarchy. I currently have the situation that a
should sometimes be visible. When do I hide the
and when do I remove it from it's superview?

Is it expensive to change the view hierarchy?


If you need to alternate between showing and hiding the subview, the best approach is definitely hiding it. For a UIButton the memory implications are not that great anyway. And the code is certainly simpler if you just switch the hidden property.

Also, you get the additional advantage that the hidden property is animatable!