search

Home  >  Q&A  >  body text

git - iOS开发隐藏一个View是直接设置hidden属性,还是将frame设置为0

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

天蓬老师天蓬老师2772 days ago1289

reply all(11)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 17:42:45

    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.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:42:45

    Setting hidden is more common.

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:42:45

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

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:42:45

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

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:42:45

    hiden is better

    reply
    0
  • 阿神

    阿神2017-04-17 17:42:45

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

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:42:45

    If there are subviews, use hidden or removefromsuperview

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:42:45

    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.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:42:45

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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:42:45

    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

    reply
    0
  • Cancelreply