UIView的表现:removeFromSuperview VS hide [英] Performance of UIView: removeFromSuperview VS hide
问题描述
这个问题非常基本。从视图层次结构中删除 UIView
并隐藏 UIView
?
This question is really basic. What is the performance difference between removing a UIView
from the view hierarchy and hiding a UIView
?
我已经读过应该从视图层次结构中删除不需要的视图。我目前的情况是有时候可以看到 UIButton
。我什么时候隐藏 UIButton
什么时候从它的超级视图中删除它?
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?
推荐答案
如果您需要在显示和隐藏子视图之间切换,最好的方法肯定是隐藏它。对于 UIButton
,内存含义无论如何都不是那么好。如果您只是切换隐藏
属性,代码肯定会更简单。
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!
这篇关于UIView的表现:removeFromSuperview VS hide的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!