2011-04-15 14 views

cevap

5

Kesinlikle. Bu yapmak clipping regions budur: Açıklamalarda belirtildiği gibi

// Save the current clipping region 
[NSGraphicsContext saveGraphicsState]; 
NSRect dontDrawThisRect = NSMakeRect(x, y, w, h); 
// Either: 
NSRectClip(dontDrawThisRect); 
// Or (usually for more complex shapes): 
//[[NSBezierPath bezierPathWithRect:dontDrawThisRect] addClip]; 
[myBezierPath fill]; // or stroke, or whatever you do 
// Restore the clipping region for further drawing 
[NSGraphicsContext restoreGraphicsState]; 
+0

NSRectClip – sergeyne

+0

sayesinde @sergeyne, düzeltilmiş fonksiyonunun doğru adıdır! –

+4

NSRectClip doğru değil. Geçerli clippath ile kesişir. Bu yüzden uyguladıktan sonra sadece dontDrawThisRect içindeki içerik çekilir, bunun yerine kırpma bölgesinden bu alan çıkarılır. Yani OP'nin istediği şeyin tam tersi. –

9

, Bay Caswell cevabı aslında OP ne sorduğunu tersidir. Bu kod örneği, bir daireden (veya başka bir bezier yolundaki herhangi bir bezier yolundan) bir rect'in nasıl kaldırılacağını gösterir. hüner kaldırmak istediğiniz yolu "ters" olduğunu, daha sonra özgün yolun sonuna ekler:

NSBezierPath *circlePath = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(0, 0, 100, 100)]; 
NSBezierPath *rectPath = [NSBezierPath bezierPathWithRect:NSMakeRect(25, 25, 50, 50)]; 
rectPath = [rectPath bezierPathByReversingPath]; 
[circlePath appendBezierPath:rectPath]; 

Not: Bezier yolları birbirini kestiği takdirde işler biraz yanıltıcıdır olsun. Sonra uygun "sarma kuralı" ayarlamalısınız.

İlgili konular