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)
When does layoutSubviews get called?的更多相关文章
- UIView的layoutSubviews和drawRect方法何时调用
首先两个方法都是异步执行.layoutSubviews方便数据计算,drawRect方便视图重绘. layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSubvi ...
- 关于layoutSubviews
layoutSubviews 是什么? 设定subviews的尺寸和位置,如果要精确布局,可以在子类里重写此方法.不能直接调用此方法,如果想强制layout刷新,调用setNeedsLayout来代替 ...
- layoutSubviews 与 drawRect
layoutSubviews总结 ios layout机制相关方法 - (CGSize)sizeThatFits:(CGSize)size- (void)sizeToFit——————- - (voi ...
- layoutSubviews方法需要被调用的情况有哪些
layoutSubviews方法:这个方法,默认没有做任何事情,需要子类进行重写 layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSubviews 但是是用i ...
- iOS开发——UI基础-自定义构造方法,layoutSubviews,Xib文件,利用Xib自定义View
一.自定义构造方法 有时候需要快速创建对象,可以自定义构造方法 + (instancetype)shopView { return [[self alloc] init]; } - (instance ...
- UIView的layoutSubviews和drawRect
原文: UIView的layoutSubviews和drawRect UIView的setNeedsDisplay和setNeedsLayout方法.首先两个方法都是异步执行的.setNeedsDis ...
- layoutSubviews #pragma mark -
>>>layoutSubviews: layoutSubviews是对sbuviews的重新布局,比如,我们想更新子视图的位置,可以通过调用layoutSubviews方法(不能直接 ...
- layoutSubviews总结
ios layout机制相关方法 - (CGSize)sizeThatFits:(CGSize)size - (void)sizeToFit ——————- - (void)layoutSubview ...
- 触发layoutSubviews的条件
1. init初始化不会触发layoutSubviews 2. addSubview会触发layoutSubviews 3. 设置view的Frame会触发layoutSubviews,当然前提是fr ...
- UIView的layoutSubviews和drawRect方法何时调用 ———转
转自:http://jianyu996.blog.163.com/blog/static/112114555201305113018814/ 首先两个方法都是异步执行.layoutSubviews方便 ...
随机推荐
- css实现三角的一些方法
css实现三角没有想象中的那么难,只要明白border的各种属性的意思就很好明白css三角是如何实现的. 一下是几个很简单的例子: css三角形状的制作: css样式: .trian ...
- MySQL账号授权操作
Mysql权限控制 - 允许用户远程连接 设置mysql root密码: mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = P ...
- 获取工程的exe文件的所在目录
Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName; 例如结果为: C:\Documents and ...
- C#面试-关于const和readonly(看了一个点赞很多的帖子有感而发!)
前景提要: 最近大家都在面试,讨论最多.最基础的问题,莫过于“关于const和readonly常见的笔试题剖析”,等等的大牛解析.我就是一个小菜,只不过,有点不敢苟同大牛的意见.废话少说,进入重点. ...
- HTML DOM(一):认识DOM
分类: HTML/JavaScript/CSS(10) 版权声明:本文为博主原创文章,转载请注明出处http://blog.csdn.net/ghsau. 什么是DOM? 通过 Jav ...
- 转:PHP开发者应了解的24个库
原文来自于:http://blog.jobbole.com/54201/ 作为一个PHP开发者,现在是一个令人激动的时刻.每天有许许多多有用的库分发出来,在Github上很容易发现和使用这些库.下面是 ...
- VmWare问题解决(网络变更后虚拟主机无法上网)
安装 Vmware,并新建一个虚拟机后,当时做好配置(NAT模式)后,虚拟机能够正常上网. 然后将电脑带到另一个地理位置办公时,却无法上网. 本篇探讨问题的缘由和几种解决方式. 一.缘由解析 仅探讨上 ...
- unity3d中脚本生命周期(MonoBehaviour lifecycle)
最近在做一个小示例,发现类继承于MonoBehaviour的类,有很多个方法,于是乎必然要问出一个问题:这么多个方法,执行先后顺序是如何的呢?内部是如何进行管理的呢?于是在网上找了许多资料,发现了Ri ...
- oracle 的一点累积
1. oracle用户相关 sqlplus sys/oracle as sysdba -- sys登录 create user xxx identified by password; -- ...
- 基于百度定位SDK的定位服务的实现
转载请标明出处:http://blog.csdn.net/android_ls/article/details/10179013 一.定位模块的需求:我们想知道使用我们应用的用户的大概位置,每隔五分钟 ...