IPhone redrawMechanism is the content to be introduced in this article, mainly to explain how to useIPhoneProceedDrawing and redrawingOperation.IPhone redrawThe Mechanism gives people the biggest feeling, strange!
IPhonePlottingOperations are completed in the drawRect method of the UIView class, so if we wantPlotting, You need to write a class that extends the UIView and override the drawRect method.PlottingThe program automatically calls this method.Plotting.
The following describes the plot first. For example, if you want to draw a square, you need to write a class to extend the UIView and fill in the following code in the drawRect method:
- Code block
-
- - (void)drawRect:(CGRect)rect
- {
- // Drawing code CGContextRef context=UIGraphicsGetCurrentContext();
- CGContextSetLineWidth(context, width);
- CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
- CGContextStrokeRect(context, CGRectMake(110.0, 110.0, 100.0, 100.0));
- CGContextStrokePath(context);
- }
The effect is as follows:
In addition, the re-painting operation is still completed in the drawRect method, but apple does not recommend that you directly call the drawRect method. Of course, if you call this method directly with rigidity, it is of course ineffective. Apple asked us to call the setNeedsDisplay method in the UIView class, then the program will automatically call the drawRect Method for re-painting. As shown in:
In, click the "circle" button to draw a circle on the screen, click the "painting" button to draw a square on the screen, drag the slider to adjust the width of the line.
Summary simple learningIPhone redrawI hope this article will help you with the introduction of the mechanism!