layoutSubviews相关AP


You should override this method only if the autoresizing behaviors of the subviews do not offer the behavior you want.layoutSubviews,


以下情况会调用layoutSubviews

  1. 修改和设置frame(不为CGRect.zero,不和oldValue相同),会调用本身和父视图的 layoutSubviews
  2. addSubview 会触发 layoutSubviews
  3. 旋转屏幕
  4. 滚动ScrollView

setNeedsLayout

  • 标记为需要重新布局,不立即刷新,但layoutSubviews一定会被调用配合layoutIfNeeded立即更新

layoutIfNeeded

  • 如果,有需要刷新的标记,立即调用layoutSubviews进行布局

results matching ""

    No results matching ""