Ios 透明层和CG层

Ios 透明层和CG层,ios,ios5,core-graphics,Ios,Ios5,Core Graphics,我正在为我的iOS5应用程序创建许多CGLayer,如下所示: layer_1 = CGLayerCreateWithContext (context,self.bounds.size, NULL); offlineContext_1 = CGLayerGetContext (layer_1); layer_2 = CGLayerCreateWithContext (context,self.bounds.size, NULL); offlineContext_2 = CGLay

我正在为我的iOS5应用程序创建许多CGLayer,如下所示:

layer_1 = CGLayerCreateWithContext (context,self.bounds.size, NULL);    
offlineContext_1 = CGLayerGetContext (layer_1);
layer_2 = CGLayerCreateWithContext (context,self.bounds.size, NULL);    
offlineContext_2 = CGLayerGetContext (layer_2);
layer_3 = CGLayerCreateWithContext (context,self.bounds.size, NULL);    
offlineContext_3 = CGLayerGetContext (layer_3);
对于计时器的每个步骤,我将绘制到脱机_上下文,当所有绘制完成后,我通过调用以下命令将所有层收集到一个中:

CGContextDrawLayerAtPoint (context, CGPointZero, layer_1);
CGContextDrawLayerAtPoint (context, CGPointZero, layer_2);
CGContextDrawLayerAtPoint (context, CGPointZero, layer_3);
这很有效。第1层的内容被第2层的内容覆盖,然后第3层覆盖前两层。所有绘图都使用以下调用完成:

    CGContextAddArc(context,cx,cy,radius,-fromDir,toDir,1-curve);
出于性能原因,我用图像替换了许多重复的绘图命令,如上面所述,因此结果应该是相同的,但我没有绘制CGContextAddArc()20次,而是告诉图像绘制自己20次:

[myArcImage drawAtPoint: loc];
然而,随着这一变化,叠加的顺序似乎发生了变化。最终,图像确实会绘制到集合视图,但只有图像的那些部分不会覆盖绘制到其他上下文的其他直线和圆弧。我在drawAtPoint变体中使用了混合,但这只会影响图像可见的部分

关于为什么直线和圆弧在其他图层中覆盖内容,而图像不覆盖内容,有什么想法吗


非常感谢

好的,我明白我在做什么了。我绘制的弧和线与上面的CGContextAddArc()调用类似,该调用将绘制的上下文作为参数。当我切换到绘图图像时,drawAtPoint()方法不将上下文作为参数。相反,它将图像绘制到当前上下文,在我的例子中,该上下文是当前UIView的上下文

我的问题的解决方案是使用push/pop上下文调用包装drawAtPoint调用:

UIGraphicsPushContext(correct_context);
[myArcImage drawAtPoint: loc];
UIGraphicsPopContext();