2012-06-07 52 views
2

我創建了一些CGLayer的爲我的iOS5的應用程序是這樣的:透明度和CGLayers

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); 

對於我提請offline_contexts定時器的每一步,當所有的繪製完成後我再收集所有通過呼叫:

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變體中使用了混合,但隻影響可見的圖像部分。

關於爲什麼線和弧疊加其他圖層內容但圖像不疊加的任何想法?

非常感謝

回答

1

好吧,它明白了我在做什麼。我繪製的弧和線與上面的CGContextAddArc()調用類似,並且該調用將參數作爲要繪製的上下文。當我切換到繪製圖像時,drawAtPoint()方法不會將上下文作爲參數。相反,它將圖像繪製到當前的上下文中,在我的情況下,它是當前UIView的上下文。

我的問題的解決方案是一個推/流行音樂情境呼叫包裹drawAtPoint電話:

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