UIView Drawing Cycle and ContentMode

本文深入解析了UIView的绘制机制,包括其按需绘制的特点及如何通过快照(snapshot)缓存来提高视图更新效率。文章解释了当UIView内容发生变化时,如何通过调用setNeedsDisplay或setNeedsDisplayInRect:方法通知系统重新绘制,并介绍了系统如何延迟执行这些绘制操作以提高性能。

UIView 的绘制模式是按需要(on-demand),当这个View第一次出现在屏幕上时,系统请求View绘制他的content,然后系统缓存该snapshot 


When a view first appears on
the screen, the system asks it to draw its content. The system captures a snapshot of this content and uses
that snapshot as the view’s visual representation. If you never change the view’s content, the view’s drawing
code may never be called again. The snapshot image is reused for most operations involving the view. If you
do change the content, you notify the system that the view has changed. The view then repeats the process
of drawing the view and capturing a snapshot of the new results.
When the contents of your view change, you do not redraw those changes directly. Instead, you invalidate the
view using either the setNeedsDisplay or setNeedsDisplayInRect: method. These methods tell the
system that the contents of the view changed and need to be redrawn at the next opportunity. The system
waits until the end of the current run loop before initiating any drawing operations. This delay gives you a
chance to invalidate multiple views, add or remove views from your hierarchy, hide views, resize views, and
reposition views all at once. All of the changes you make are then reflected at the same time


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值