View & draw
When an iOS application is launched, it starts a run loop. The run loop’s job is to listen for events,
such as a touch. When an event occurs, the run loop then finds the appropriate handler methods for the
event. Those handler methods call other methods, which call more methods, and so on. Once all of the
methods have completed, control returns to the run loop.
When the run loop regains control, it checks a list of “dirty views” – views that need to be rerendered
based on what happened in the most recent round of event handling. The run loop then sends
the drawRect: message to the views in this list before all of the views in the hierarchy are composited
together again.
These two optimizations – only re-rendering views that need it and only sending drawRect: once per
event – keep iOS interfaces responsive.
To get a view on the list of dirty views, you must send it the message setNeedsDisplay. The
subclasses of UIView that are part of the iOS SDK send themselves setNeedsDisplay whenever their
content changes.
For example, an instance of UILabel will send itself setNeedsDisplay when it is sent
setText:, since changing the text of a label requires the label to re-render its layer. In custom UIView
subclasses, you must send this message yourself.
There is another possible optimization when redrawing: you can mark only a portion of a view as
needing to be redrawn. This is done by sending setNeedsDisplayInRect: to a view.
Often, you will want to do some extra initialization of the subviews that are defined in the XIB file
before they appear to the user. However, you cannot do this in the view controller’s initializer
because the NIB file has not yet been loaded. If you try, any pointers that the view controller declares
that will eventually point to subviews will be pointing to nil. The compiler will not complain if you
send a message to one of these pointers, but whatever you intended to happen to that view object will
not happen.
So where can you access a subview? There are two main options, depending on what you need to do.
The first option is the viewDidLoad method that you overrode to spot lazy loading. The view
controller receives this message after the view controller’s NIB file is loaded, at which point all of
the view controller’s pointers will be pointing to the appropriate objects. The second option is
another UIViewController method viewWillAppear:. The view controller receives this message just
before its view is added to the window.
What is the difference? You override viewDidLoad if the configuration only needs to be done once
during the run of the app. You override viewWillAppear:
if you need the configuration to be done and
redone every time the view controller appears on screen.
View & draw的更多相关文章
- 自定义View Draw过程(4)
目录 目录 1. 知识基础 具体请看我写的另外一篇文章:自定义View基础 - 最易懂的自定义View原理系列 2. draw过程作用 绘制View视图 3. draw过程详解 同measure.la ...
- View学习(四)-View的绘制(draw)过程
View的draw过程相比之于measrue过程,也是比较简单的.并且在我们自定义View时,也经常需要重写onDraw方法,来绘制出我们要实现的效果. 如之前的文章所说,绘制的流程也是起始于View ...
- Activtiy完全解析(三、View的显示过程measure、layout、draw)
转载请标明出处: http://blog.csdn.net/xmxkf/article/details/52840065 本文出自:[openXu的博客] 在Activity完全解析的第一篇文章A ...
- Android View框架总结(六)View布局流程之Draw过程
请尊重分享成果,转载请注明出处: http://blog.csdn.net/hejjunlin/article/details/52236145 View的Draw时序图 ViewRootImpl.p ...
- Android View 绘制流程(Draw) 完全解析
前言 前几篇文章,笔者分别讲述了DecorView,measure,layout流程等,接下来将详细分析三大工作流程的最后一个流程——绘制流程.测量流程决定了View的大小,布局流程决定了View的位 ...
- Android View 的绘制流程之 Layout 和 Draw 过程详解 (二)
View 的绘制系列文章: Android View 的绘制流程之 Measure 过程详解 (一) Android View 绘制流程之 DecorView 与 ViewRootImpl 在上一篇 ...
- 虾扯蛋:Android View动画 Animation不完全解析
本文结合一些周知的概念和源码片段,对View动画的工作原理进行挖掘和分析.以下不是对源码一丝不苟的分析过程,只是以搞清楚Animation的执行过程.如何被周期性调用为目标粗略分析下相关方法的执行细节 ...
- 深入理解 Android 之 View 的绘制流程
概述 本篇文章会从源码(基于Android 6.0)角度分析Android中View的绘制流程,侧重于对整体流程的分析,对一些难以理解的点加以重点阐述,目的是把View绘制的整个流程把握好,而对于特定 ...
- Android View的绘制流程
写得太好了,本来还想自己写的,奈何肚里墨水有限,直接转吧.正所谓前人种树,后人乘凉.. View的绘制和事件处理是两个重要的主题,上一篇<图解 Android事件分发机制>已经把事件的分发 ...
随机推荐
- 面试题---PHP
1.PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言. 2.echo,print和print_r的区别: echo和print都可以做 ...
- 第二章:UNIX标准化及实现
本章节介绍个UNIX编程环境的标准化的进展,对ISO C,POSIX和Single UNIX Specification三个主要标准进行了说明 本章后面部分介绍了限制的具体实例. 我学习本章的心得是: ...
- 99乘法表(bash)
awk方式: # awk 'BEGIN{for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf j"x"i"="i*j ...
- SpringMvc 页面DATE传值问题
页面传过来yyy-MM-dd格式的日期类型,springMVC是不认的. 解决办法: @DateTimeFormat(pattern="yyyy-MM-dd") 在类属性上加上注解 ...
- job history 的查看
linux shell 可以启动 mapred historyserver 然后根据显示的端口hostname+port进行访问(一般默认端口是19888)
- S3C2416 看门狗
原理:看门狗自己有个硬件计数器,看门狗开启后,计数器就开始计数,当计数为0时触发,触发事件有两个:系统复位和中断,可设置屏蔽. 在计数器计数到0之前,程序可以重新设置计数器中的数值,称之喟狗.计数器的 ...
- Java Concurrent之 AbstractQueuedSynchronizer
ReentrantLock/CountDownLatch/Semaphore/FutureTask/ThreadPoolExecutor的源码中都会包含一个静态的内部类Sync,它继承了Abstrac ...
- webstorm 10 出现不能run cordova项目
could not create the java virtual machine Error occurred during initialization of VM Could not reser ...
- Python Iterable Iterator Yield
可以直接作用于for循环的数据类型有以下几种: 一类是集合数据类型,如list / tuple / dict / set / str /等(对于这类iterable的对象,因为你可以按照你的意愿进行重 ...
- CentOS MySQL 配置
问题: MySQL安装后root用户无法连接,提示 ERROR 1045 (28000): Access denied for user ’root’@’localhost’ (using passw ...