zoukankan      html  css  js  c++  java
  • When does layoutSubviews get called?

    转自:http://blog.logichigh.com/2011/03/16/when-does-layoutsubviews-get-called/

    It’s important to optimize any UIView layoutSubviews method you create, as it can be frequently called, and has the potential for creating recursion (triggering a setNeedsLayout from layoutSubviews can create a loop that will grossly affect your apps performance). Layout subviews is called once per run loop on any view that has had setNeedsLayout or setNeedsDisplayWithRect: called on it. So in addition to any time you manually call these methods, it can be useful to know when the UI framework calls setNeedsLayout/setNeedsDisplay as this will trigger layoutSubviews.

    For this purpose, I will define a few view relationships:

    • View1 – UIView class, root view for examples
    • View1.1 – UIScrollView class, subview of View1
    • View1.1.1 – UIView class, subview of View1.1 (No autoresize mask)
    • View1.1.2 – UIView class, another subview of View1.1 (Autoresize mask – flexible width)

    I then ran the following tests.  An X means the view was layed out

    From this I surmise the following:

    • 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 it’s frame set only if the size parameter of the frame is different
    • scrolling a UIScrollView causes layoutSubviews to be called on the scrollView, and it’s superview
    • rotating a device only calls layoutSubview on the parent view (the responding viewControllers primary view)
    • removeFromSuperview – layoutSubviews is called on superview only (not show in table)
  • 相关阅读:
    CSS盒子模型
    getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
    MYSQL中的CASE WHEN END AS
    单点登录的精华总结
    git&github
    June 21st 2017 Week 25th Wednesday
    June 20th 2017 Week 25th Tuesday
    June 19th 2017 Week 25th Monday
    June 18th 2017 Week 25th Sunday
    June 17th 2017 Week 24th Saturday
  • 原文地址:https://www.cnblogs.com/xjshi/p/4610430.html
Copyright © 2011-2022 走看看