layoutSubviews何时被调用

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.

 

layoutSubviews 在以下情况下会被调用:
1、init 初始化不会触发 layoutSubviews

2、addSubview 会触发 layoutSubviews

3、设置 view 的 Frame 会触发 layoutSubviews,当然前提是 frame 的值 (size) 设置前后发生了变化

4、滚动一个 UIScrollView 会触发 layoutSubviews

5、旋转 Screen 会触发父 UIView 上的layoutSubviews 事件

6、改变一个 UIView size 的时候也会触发父 UIView 上的 layoutSubviews 事件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值