0

В этом коде я использую CGContextRef создать следующую картину на моем UIView:Добавить изображение, которое рисует UIBezier или CGContextRef в UIView подслоя

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); 

Но я хочу, чтобы преобразовать в с CATransform3D. Для этого я должен нарисовать этот контекст в подслое моего UIView (потому что я хочу нарисовать больше подслоев на нем UIView). Как я могу нарисовать этот путь CGContextRef в отдельном подслое UIView?

ответ

0

исправить его следующей конструкции:

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 - свойство суперкласса с типом CAShapeLayer. Это работает, но результат выглядит без сглаживания (с необработанной пикселизацией). enter image description here

Как это можно исправить и сделать изображение более гладким?

P.S .: эта проблема возникает, когда я пытаюсь преобразовать CGContext в CAShapeLayer. В первом примере, когда я делаю это с CGContext, этой проблемы не было. (Вы можете посмотреть его в первом примере на верхнем посту)

 Смежные вопросы

  • Нет связанных вопросов^_^