When is layoutSubviews called?

I had a similar question, but wasn’t satisfied with the answer (or any I could find on the net), so I tried it in practice and here is what I got:

  • init does not cause layoutSubviews to
    be called (duh)
  • addSubview: causes
    layoutSubviews to be called on the
    view being added, the view it’s being
    added to (target view), and all the
    subviews of the target
  • view setFrame
    intelligently calls layoutSubviews on
    the view having its frame set only
    if the size parameter of the frame is
    different
  • scrolling a UIScrollView
    causes layoutSubviews to be called on
    the scrollView, and its superview
  • rotating a device only calls
    layoutSubview on the parent view (the
    responding viewControllers primary
    view)
  • Resizing a view will call layoutSubviews on its superview (Important: views with an intrinsic content size will re-size if the content that determines their size changes; for example, updating the text on a UILabel will cause the intrinsic content size to be updated and thus call layoutSubviews on its superview)

My results – http://blog.logichigh.com/2011/03/16/when-does-layoutsubviews-get-called/

Leave a Comment