1.当一个类是UIView或UIView的子类时,这个类会调用drawRect:用来绘制显示在手机屏幕的图片,通常我们把自定义的绘图时,会覆盖此方法并把代码写在这个方法里,每当UIView的实例要绘图或重绘时,系统会为这个View准备一个绘图上下文,然后这个上下文会被激活,drawRect:消息会被发送。绘图上下文的类型是CGContextRef负责合成绘图命令和生成图片,保存绘图状态。当我们调用UIKit框架中的类和方法,这是会隐式地使用当前激活的绘图上下文。在其他情况下你需要取得绘图上下文,然后调用Core Graphics框架的C函数来绘图。(Each time an instance of UIView needs to be drawn (or redrawn), the system prepares a graphics context specifically for that view. Then the context is activated, and the message drawRect: is sent to the instance of UIView that is being drawn. The graphics context’s type is CGContextRef (Core
Graphics Context Reference), and it is responsible for aggregating drawing commands and producing an image as a result. This image is the appearance of the view instance. A graphics context also stores its drawing state, which includes things like the current drawing color, coordinate system, and the
current line width.)
drawRect:一点绘图知识总结
最新推荐文章于 2022-02-14 01:46:57 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)