2013-10-14 26 views
8

Ich habe einige CGPath (ein Poly mit zwei Kreisen) auf einem CAShapeLayer durchgeführt.Trimmen/subtrahieren CGPath von CGPath?

Kann ich Pfade wie diese trimmen/subtrahieren?

enter image description here

+0

Kurze Antwort: Nein. Lange Antwort: Sie können, aber es ist ziemlich schwer. –

+0

Danke :) Ich kann es tun, indem ich Ebenenmaske als Fallback hinzufüge, aber ich wollte Rasterisierung Pässe unterdrücken, würde Mathematik bevorzugen. – Geri

+1

+1 für die Zeichnung – Norbert

Antwort

4

Statt die Mathematik zu tun, kann das Ergebnis bei Ziehzeit kCGBlendModeClear mit erreicht werden.

// Create the poly. 
CGContextBeginPath(context); 
CGContextMoveToPoint  (context, a_.x, a_.y); 
CGContextAddLineToPoint (context, b_.x, b_.y); 
CGContextAddLineToPoint (context, c_.x, c_.y); 
CGContextAddLineToPoint (context, d_.x, d_.y); 
CGContextClosePath(context); 

// Draw with the desired color. 
CGContextSetFillColorWithColor(context, self.color.CGColor); 
CGContextFillPath(context); 

// Create a circle. 
CGContextBeginPath(context); 
CGContextAddEllipseInRect(context, (CGRect){ 
    b_.x - self.radius, 
    b_.y - self.radius, 
    self.radius * 2.0, 
    self.radius * 2.0 }); 
CGContextClosePath(context); 

// Draw with Clear (!) blend mode. 
CGContextSetBlendMode(context, kCGBlendModeClear); 
CGContextSetFillColorWithColor(context, self.color.CGColor); 
CGContextFillPath(context);