git - iOS开发隐藏一个View是直接设置hidden属性,还是将frame设置为0
天蓬老师
天蓬老师 2017-04-17 17:40:45
0
11
1297

这两种方式,效果一样?我指的是性能方面

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(11)
大家讲道理

Modifying the frame of a view, or removing the view from the parent view will directly cause the view's layoutSubviews method to be called, and if the contentMode is set to UIViewContentModeRedraw, it will also cause the drawRect method to be called. At this time, if you customize these two methods to do some drawing and layout work, the CPU and GPU will be consumed to do your work.

So, if you just want to hide the view, just use the hidden attribute directly.

刘奇

Setting hidden is more common.

迷茫

It’s the same for users, but the system’s hidden version is more reliable.

黄舟

You can do this [self.xxx removeFromSuperview], it depends on the demand

大家讲道理

hiden is better

阿神

After being hidden, he still has to occupy his position, and his related constraints also exist. It depends on the demand

大家讲道理

If there are subviews, use hidden or removefromsuperview

Peter_Zhu

Under normal circumstances, it is better to use hidden, but if there are constraints that need to be changed or layoutsubview is required, it is better to remove or change the frame.

Peter_Zhu

If you want to hide, just set hidden. Otherwise, the name hidden directly translates to hidden, so there is no need to do anything~

伊谢尔伦

Generally hidden is more reliable because you don’t need to change the original frame. When you need to display it again, you can just modify the attributes directly. Changing the frame every time is not only slow but also modifies the original control. For constraints, if you change the frame, you don't need to re-constraint, otherwise you have to uninstall the constraint. Let’s look at each situation

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template