2013-09-06 22 views
6

Bir CGContext için çizim ve CGImageRef tabanlı maske kullanıyorum: CGContext ile ilişkili kırpma maskesini nasıl sıfırlayabilirim veya temizleyebilirim?

CGContextRef context = UIGraphicsGetCurrentContext(); 

CGContextClipToMask(context, rect, _firstMaskImageRef); 
CGContextSetFillColorWithColor(context, color); 
CGContextFillRect(context, rect); 

O zamana geçmek istediğiniz ikinci maske:

CGContextClipToMask(context, rect, _secondMaskImageRef); 
CGContextSetFillColorWithColor(context, color); // color has changed FWIW 
CGContextFillRect(context, rect); // as has rect 

Fakat, bu iki kesişen İlk yerine yerine maskeler.

Bir CGContext için kırpma maskesini nasıl temizleyebilir veya sıfırlayabilirsiniz?

cevap

15

Sen kırpma maskesi ayarlamadan önce bir grafik durumu kaydedin ve sonra bu gibi sonradan sıfırlayabilirsiniz: (? 3+) Swift

CGContextSaveGState (context); 
...Set your first clipping mask, fill it, etc. 
CGContextRestoreGState (context); 
...Do other stuff 
0

Sonraki sürümlerinde yerine aşağıdaki sözdizimini kullanın:

0

context.saveGState() 
// set your clipping mask, etc. 
context.restoreGState() 
// everything's back to normal 
, kırpma maskesi sıfırlamak için kullanın:

CGContextResetClip(context); 
İlgili konular