圖形上下文

大美女
1. 圖形上下文概述
圖形上下文(Graphics Context)是什么井氢?
是一個CGContextRef 類型的數(shù)據(jù)圖形上下文的作用
- 保存繪圖信息丶繪圖狀態(tài)
- 決定繪制的輸出目標(即繪制的圖到哪里)
相同的一套繪圖序列妈拌,指定了不同的Graphics Contents,就可以把相同的圖像繪制到不同的目標上
Quartz2D提供了以下幾種類型的Graphics Context:
- Bitmap Graphics Context
- PDF Graphics Context
- Window Graphics Context
- Layer Graphics Context
- Printer Graphics Context
- 自定義UIView
- 需要一個繼承自UIView的類
- 需要重寫這個自定義類的- (void)drawRect:(CGRect)rect方法 (因為在drawRect:方法中才能取得跟view相關(guān)聯(lián)的圖形上下文)
- drawRect:方法在什么時候被調(diào)用?
- 當view第一次顯示到屏幕上時(被加到UIWindow上顯示出來)
- 調(diào)用view的setNeedsDisplay或者setNeedsDisplayInRect:時
2. Quartz2D 的描述
- Quartz2D的API是純C語言
- Quartz2D的API來自于Core Graphics框架
- 數(shù)據(jù)類型和函數(shù)基本都以CG作為前綴
CGContextRef
CGPathRef
CGContextStrokePath(ctx);
……