Iphone 如何在剪切后将上下文重置为原始矩形进行绘图?

Iphone 如何在剪切后将上下文重置为原始矩形进行绘图?,iphone,Iphone,我尝试绘制一系列模式图像(一个视图中的不同重复模式) 所以我做的是,在一个循环中: 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 work

我尝试绘制一系列模式图像(一个视图中的不同重复模式)

所以我做的是,在一个循环中:

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]);
我想,在我裁剪了上下文以在特定的矩形中绘制图案之后,我从大画布上剪下了一个片段,下一次,我的画布就不见了。无法删除另一个片段。所以我必须以某种方式重新设置剪辑,以便能够在其他地方再次绘制另一个图案

编辑:在文档中,我发现:

CGContextClip:“……因此 将可喷漆区域重新放大 将剪切路径恢复到先前的路径 状态,则必须保存图形 在剪辑和还原前先进行状态设置 完成后的图形状态 任何剪裁过的图纸……”


那么,在剪辑之前如何存储图形状态以及如何恢复它呢?

您正在寻找的功能有:

CGContextSaveGState(context);

CGContextRestoreGState(context);