美文网首页
setNeedsLayout、layoutIfNeeded和la

setNeedsLayout、layoutIfNeeded和la

作者: 奥个特曼 | 来源:发表于2015-12-14 18:47 被阅读54次
layoutSubviews在以下情况下会被调用:
  • init初始化不会触发layoutSubviews,但是是用initWithFrame 进行初始化时,当rect的值不为CGRectZero时,会触发
  • addSubview会触发layoutSubviews
  • 设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化
  • 滚动一个UIScrollView会触发layoutSubviews
  • 旋转Screen会触发父UIView上的layoutSubviews事件
  • 改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件

在苹果的官方文档中强调:
You should override this method only if the autoresizing behaviors of the subviews do not offer the behavior you want.layoutSubviews, 当我们在某个类的内部调整子视图位置时,需要调用。
反过来的意思就是说:如果你想要在外部设置subviews的位置,就不要重写。

相关文章

网友评论

      本文标题:setNeedsLayout、layoutIfNeeded和la

      本文链接:https://www.haomeiwen.com/subject/tgjuhttx.html