How to reset the context of the original rectangle after cropping it for drawing?

I am trying to draw a sequence of pattern images (different repeating patterns in one view).

So, I did this in a loop:

CGContextRef context = UIGraphicsGetCurrentContext(); // clip to the drawing rectangle to draw the pattern for this portion of the view CGContextClipToRect(context, drawingRect); // the first call here works fine... but for the next nothing will be drawn CGContextDrawTiledImage(context, CGRectMake(0, 0, 2, 31), [img CGImage]); 

I think that after I cut the context to draw a pattern in a specific rectangle, I cut a fragment from a large canvas, and the next time my canvas disappeared. cannot cut another fragment. So, should I reset something to crop so that I can draw another drawing again somewhere else?

Edit: in the documentation, I found this:

CGContextClip: "... Therefore, to recolor the restoration area of ​​the cropping path to a state, you must save the graphics before the clip and restore the state of the graphic after you have completed any cropped drawing ...."

So, how to save the state of the graphics before cropping and how to restore it?

+4
source share
1 answer

Features you are looking for:

 CGContextSaveGState(context); 

and

 CGContextRestoreGState(context); 
+20
source

Source: https://habr.com/ru/post/1306136/


All Articles