0

In diesem Code Zeichnung I CGContextRef verwenden nächstes Bild auf meinem UIView zu erstellen:Bild hinzufügen, die mit UIBezier oder CGContextRef in UIView Unterschicht

http://imgur.com/gPtBAEO

CGMutablePathRef arc = CGPathCreateMutable(); 
CGFloat lineWidth = 16.0; 
CGContextRef cont = UIGraphicsGetCurrentContext(); 
CGContextFlush(cont); 
CGContextSetStrokeColorWithColor(cont, [UIColor grayColor].CGColor); 
CGContextSetFillColorWithColor(cont, [UIColor clearColor].CGColor); 

for (int i = 0; i < 16; i++) { 
    CGPathAddArc(arc, NULL, cenPoint.x, cenPoint.y, halfWidthInc(-8.0f), DEG_TO_RAD(_deg1*i), DEG_TO_RAD(_deg1*(i+1)), NO); 
    CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, lineWidth, kCGLineCapButt, kCGLineJoinMiter, 10); 
    CGContextAddPath(cont, strokedArc); 
} 

for (int i = 0; i < 8; i++) { 
    arc = CGPathCreateMutable(); 
    CGPathAddArc(arc, NULL, cenPoint.x, cenPoint.y, halfWidthInc(-24.0f), DEG_TO_RAD(_deg2*i), DEG_TO_RAD(_deg2*(i+1)), NO); 
    CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, lineWidth, kCGLineCapButt, kCGLineJoinMiter, 10); 
    CGContextAddPath(cont, strokedArc); 
} 

for (int i = 0; i < 4; i++) { 
    arc = CGPathCreateMutable(); 
    CGPathAddArc(arc, NULL, cenPoint.x, cenPoint.y, halfWidthInc(-40.0f), DEG_TO_RAD(_deg3*i), DEG_TO_RAD(_deg3*(i+1)), NO); 
    CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, lineWidth, kCGLineCapButt, kCGLineJoinMiter, 10); 
    CGContextAddPath(cont, strokedArc); 
} 

for (int i = 0; i < 2; i++) { 
    arc = CGPathCreateMutable(); 
    CGPathAddArc(arc, NULL, cenPoint.x, cenPoint.y, halfWidthInc(-56.0f), DEG_TO_RAD(_deg4*i), DEG_TO_RAD(_deg4*(i+1)), NO); 
    CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, lineWidth, kCGLineCapButt, kCGLineJoinMiter, 10); 
    CGContextAddPath(cont, strokedArc); 
} 


CGContextDrawPath(cont, kCGPathFillStroke); 

Aber ich will mit CATransform3D verwandeln in. Dafür muss ich diesen Kontext im Sublayer meiner UIView zeichnen (weil ich mehr Sublayer darauf zeichnen möchte). Wie kann ich diesen CGContextRef Pfad in separaten Sublayer von UIView zeichnen?

Antwort

0

Ich fixiere es mit dem nächsten Bau:

CGPathRef *board = CGContextCopyPath(cont); 

_indi1 = [CAShapeLayer layer]; 
_indi1.frame = self.layer.bounds; 
_indi1.bounds = CGRectInset(pathCont, 0, 0); 
_indi1.geometryFlipped = YES; 
_indi1.path = board; 
_indi1.strokeColor = [[UIColor colorWithRed:125.0f/255.0f green:251.0f/255.0f blue:181.0f/255.0f alpha:1] CGColor]; 
_indi1.fillColor = nil; 
_indi1.lineWidth = 1.0f; 
_indi1.fillRule = kCAFillRuleEvenOdd; 
_indi1.lineJoin = kCALineJoinRound; 

[self.layer insertSublayer:_indi1 atIndex:0]; 

_indi1 - Eigentum der übergeordneten Klasse mit CAShapeLayer Typ. Es funktioniert, aber Ergebnis sieht ohne Glättung (mit rohen Pixilierung). Gefällt mir: enter image description here

Wie kann ich es beheben und Bild weicher machen?

P.S .: Dieses Problem Popup, wenn ich versuche, CGContext in CAShapeLayer zu konvertieren. Im ersten Beispiel, wenn ich es mit CGContext mache, ist dieses Problem nicht aufgetreten. (Sie können es im ersten Beispiel am oberen Pfosten schauen)

Verwandte Themen