1> quartz2d Introduction
* PPT Introduction
What is quartz2d? Two-dimensional drawing engine
What is two-dimensional?
What is an engine? A packaged library of functions that is easy for developers to use. Which means that Apple helped us encapsulate a set of drawing libraries.
What does it mean to support both iOS and Mac systems? The same code written in quartz2d can be run on iphone and on Mac and can be developed across platforms.
A screenshot/crop/custom UI control is more commonly used in development.
The value of quartz2d in iOS development is the custom UI control.
The data type and function of the graphics context.
How many of these are planted below.
The steps for customizing the control.
Why implement the DrawRect: method, because the context is only available in the DrawRect: method
2> quartz2d Drawing Walkthrough
Where's the painting? Storyboard Drag a view to draw something in this view.
Custom view: You must rewrite the drawrect if you need to draw: method
* Hmlineview: Drawing segment must draw analysis
DrawRect: What does the method automatically generate, and what does it mean? This method is important.
1> when to call: When the view is to be displayed, it is called only after viewdidload, because the view is not yet displayed.
2> effect: Used to draw
* Draw a line
1> Getting the graphics context
CG: Represents this class in the Coregraphics framework Ref: Reference
The current learning context is related to Uigraphics, want to get the graphics context, first knock Uigraphics.
2> stitching Path: In general development with a Bezier path, which encapsulates a lot of things, you can help me draw some basic lines, rectangles, circles and so on.
Create a Bezier path
Starting point: moveToPoint
End point: Addlinetopoint
3> adding a path to the context
Cgpath Conversion: Uikit frame turn Coregraphics direct Cgpath can turn
4> renders the context to the view, and the graphics context itself does not have a display function.
PPT Drawing Analysis Why do you do this? First get the graphics context, then describe the path, add the path to the context, render to the view, the graphics context is equivalent to a memory buffer, in memory operation is the fastest, more than directly in the interface operation faster.
* Add a line
Direct Addlinetopoint, because the path is spliced, the default is the beginning of the next line is the end of the previous line.
* Draw two lines that are not connected
1> the second time, reset the starting point and draw the line. A path can contain more than one segment.
2> creates a new path that is added to the context. This is recommended in development, and it is easier to control each line.
* Set Drawing status
How to add a thick line.
Drawing status Call order: As long as it is good before rendering, you will see the final state of the drawing when rendering.
* Draw Curves
PPT Analysis: 3 points, starting point, end point, control point.
* Hmshapeview: Drawing graphics
* Triangle triangle (drawing analysis)
* Close path Closepath: Connect to start point from end of path
* Fill path Cgcontextfillpath: Can be filled with closed paths.
* Set Fill color [[Uicolor Bluecolor] setfill];
* Set stroke color [[Uicolor Redcolor] setstroke];
* Do not display stroke color, why? No line width set
* Set the line width, or do not show, why? Because the drawing path is not correct.
* That is, fill and stroke cgcontextdrawpath:kcgpathfillstroke.
* Rectangle Rectangle
* Circle Circle: Why the rectangle is passed in because the circle is tangent to the rectangle
* Arc Arc
PPT Analysis:
1> arcs are part of a circle, so you have to have a circle first to have an arc.
Does the 2> circle need a starting point? Draw line need, circle also not additional.
Where is 3> starting point? Center Right
4> Draw arc also need to start angle, end angle, direction, angle must be radian
* Quarter 1/4 Yuan
* Draw a 1/4 arc, Stroke
* Fill Path, fill
* Must have a closed path to fill, no closed path, the system will automatically close the path, and then to fill
* Draw the line to connect the center, automatically close the path.
2.1 Basic graphic drawing:
First draw ppt in writing code
Order of instruction: Draw line: Draw straight lines, draw two straight lines (path fill, set path properties, color, lineweight, etc.)
Instruction order: Drawing (Shape): Drawing triangle (Superman's underwear)--round-shaped circular arc->1/4
3> Redraw-Download progress bar (Setneedsdisplay) must draw analysis
* Analysis has several controls: Uisliderview, custom view for drawing, UILabel
* Analysis ideas: When sliding uisliderview, the value of Uisliderview to the custom view, change the display.
* How to monitor Uisliderview,valuechange events
* Custom view to engage a property to receive sliding values
* Next the label, because he is relatively simple, to do things, first from a simple start.
* Lazy load Label, center position, Text Center
* Label how to display? Override Progress's Set method, with the data displayed on the label.
* Draw arcs, PPT analysis, starting from where to draw arcs.
* How many degrees per turn? Angle = Progress * M_PI * 2
* StartAngle =-m_pi_2
* Endangle =-m_pi_2 + Progress * M_PI * 2
* Does not update the view display in time? Why, because DrawRect is only called once when the view is displayed.
* How to redraw?
* Call the DrawRect method manually, no, because you cannot create the context yourself, you must call the system to invoke
* Setneedsdisplay: To make a redraw mark on the view, the next time the drawing cycle arrives, the context is created first, and then the drawrect is automatically called to redraw.
4> Drawing a pie chart
* The conclusion of Starta,enda,angle is drawn from the law----The PPT analysis
* Starta = ENDA angle = proportional * Total number of degrees 360°enda = Starta + angle
* angle = self/100.0 * 360
* A fan-shaped picture
5> drawing a bar chart
* The conclusion of W,H,Y,X is drawn from the law----The PPT analysis
* W = VIEWW/(2 * count-1)
* H = viewh * ratio
6> Uikit Encapsulation Drawing Method Walkthrough (no context Required)
6.0 Drawing Text
6.1 drawing rectangles
6.2 Drawing Images
6.4 Image Trimming, after you specify a trimmed area, all the drawing information displays only the trim area
7> Imitation uiimageview/snowflake (timer)
8> Graphics Context stack
9> Matrix Transformation
Detailed introduction to quartz2d use in iOS development