This question is really basic. What is the performance difference between removing a UIView
from the view hierarchy and hiding a UIView
?
I have read that Views that are not needed should be removed from the view hierarchy. I currently have the situation that a UIButton
should sometimes be visible. When do I hide the UIButton
and when do I remove it from it's superview?
Is it expensive to change the view hierarchy?
I've done an experiment on iOS6 iPad mini, with a large scroll view that has a lot of rich content (including images, drop shadows, gradient layers, patterned background images, you know, those designers:) ) and I found that view.hidden=YES ≠ [view removeFromSuperview].
I originally thought that setting hidden to YES will make the view not being render/drawn, therefore having a lot of hidden views will have no impact on efficiency. But the actual result is: 1) if I set the offscreen views in the big scroll view to hidden (and unhide them when they come back into visible area), the scrolling is not smooth/continuous at all. When it's naturally decelerating it looks very jumpy. 2) if I remove the offscreen views from the scroll view (but still keep in memory with a tracking array, so when they come back in they can be added immediately), the scrolling is obviously smoother.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With