2013-07-23 3 views
0

내가 정의 CALayer 클래스의 drawLayer 방법으로 호를 그리 아래의 코드를 사용하고 있지만 아무것도 표시되지 않습니다의 CALayer drawLayer inContext에 표시되지 :UIBezierPaths는

(void) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx 

{ 
    float r = self.bounds.size.width/2; 

    CGContextClearRect(ctx, self.bounds); // clear layer 
    CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); 

    //CGContextFillRect(ctx, layer.bounds); 

    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(0, 0) radius:r startAngle:-M_PI_2 endAngle:M_PI_2 clockwise:NO]; 

    CGContextAddPath(ctx, path.CGPath); 
    CGContextStrokePath(ctx); 
} 

참고가 나는 CGContextFillRect(ctx, layer.bounds)의 주석을 해제하는 경우 직사각형이 제대로 렌더링됩니다. 당신이 채우기 그것이 에 사용되는 색상을 채우기 경로를 구성 할 때 내가 볼 수

+1

획 색상이 누락 되었습니까? –

답변

0

문제는 당신이 뇌졸중 색상 (그러나 채우기 색상)

CGContextSetStrokeColorWithColor(ctx, [UIColor redColor].CGColor); 

를 설정하지 않는다는 것입니다. 획 색상과 동일합니다. 당신은 단지 당신은 당신이 모두를 수행하려는 경우 중 하나CGContextStrokePath 또는 CGContextFillPath하지만 당신은 "그리기 모드"로 kCGPathFillStrokeCGContextDrawPath를 사용해야합니다 를 사용해야 하나 스트로크 원하거나 경로를 입력 할 경우


.

0

두 분 모두에게 감사드립니다. 내가 마지막으로 다음 코드를 사용하여 drawLayer 방법 이외의 호를 그리하기로 결정

그것은 CGPath 및 UIBezierPath 두 방법을 그리기 호는 64 개 비트 디바이스에 버그가있는 모든처럼 보이는
- (id) initWithLayer:(id)layer withRadius:(float)radius 
{ 
    self = [super initWithLayer:layer]; 

    // ... 

    self.strokeColor = [UIColor whiteColor].CGColor; 
    self.lineWidth = 10.0; 

    return self; 
} 

- (void) update:(float)progress 
{ 
    // .... 

    UIBezierPath *arcPath = [UIBezierPath bezierPath]; 
    [arcPath addArcWithCenter:CGPointMake(r, r) radius:r - self.lineWidth/2 startAngle:startAngle endAngle:nextAngle clockwise:YES]; 
    self.path = arcPath.CGPath; 
} 
0

그들은 단지 시계 경우 일하는 곳 매개 변수가 YES로 설정됩니다. 작동하지 않는 코드는 clockwise:NO이고 작동 코드는 clockwise:YES입니다.