2009-10-23 33 views
0

我有這樣的代碼:CGImageRef和圖形層

CGDataProviderRef provider = CGDataProviderCreateWithFilename([myFile UTF8String]); 
CGImageRef img = CGImageCreateWithJPEGDataProvider(provider, NULL, true, kCGRenderingIntentDefault); 

後來我加載CGImageRef在一個UIImage這樣:

UIImage *uiImage = [[UIImage alloc] initWithCGImage:destImage]; 

我想上繪製該圖像的圓。重點是圓圈移動,所以它必須被刪除和重繪。我想實現這一目標的最好方法是使用圖層,所以我的問題是:如何將圖層添加到該代碼並在其上繪製一個圓圈?我以後如何重置圖層並重繪該圓圈?

謝謝!

回答

0

您將需要使用UIImageView,然後向該視圖添加單獨的圖層。如果圖層[circle]移動,只需將其位置屬性設置爲新中心;視圖系統將負責重新組合所有內容。

要讓你的圓圈出現在圖層中,你可以使用固定圖像,CALayer子類並重寫drawInContext :,或者設置委託並實現drawLayer:inContext :.