UIView的表现:removeFromSuperview VS hide [英] Performance of UIView: removeFromSuperview VS hide

查看:89
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆