- Quartz 2D is a two-dimensional drawing engine that supports both iOS and Mac systems
- Quartz 2D can do the work
1. Drawing: line \ triangle \ rectangle \ Circle \ Arc, etc.
2. Drawing text
3. Draw \ Generate picture (image)
4. read \ Generate PDF
5. \ crop a picture
6. Custom UI Controls ...
- The value of quartz2d in iOS development
Use the controls provided by the Uikit framework to cobble together, build and present some simple, common UI interfaces
However, some UI interfaces are extremely complex and more personalized and cannot be implemented with normal UI controls, so you can use quartz2d technology to draw the structure inside the control and customize what the control looks like
In fact, the contents of most controls in iOS are drawn through quartz2d.
As a result, quartz2d is an important value in iOS development: Custom view (custom UI controls)
- Graphics context: is a cgcontextref type of data
The role of the graphics context
1. Save drawing information, drawing status
2. Decide where to draw the output target (where to draw?) (The output target can be a PDF file, a bitmap, or a display window)
1. Create a new class that inherits from UIView
2. Implement-(void) DrawRect: (CGRect) Rect method, and then in this method
3. Get the graphical context associated with the current view
4. Draw the appropriate graphic content
5. Render all rendered content to the view using the graphical context
Why implement DrawRect: How can I draw to a view?
Because the graphics context associated with the view can be obtained in the DrawRect: method
After you get the context in the DrawRect: method, you can draw something to the view
There is a layer property inside the view, DrawRect: A layer Graphics Context is obtained in the method, so the drawing is actually drawn to the view layer.
View is able to show things entirely because of its inner layer
DrawRect: When is the method called?
1. When the view is displayed on the screen for the first time (it is added to the UIWindow)
2. Call the view's Setneedsdisplay or Setneedsdisplayinrect: when
QUARTZ2D Study Summary