2012-08-28 1 views
1

나는 ipad에 간단한 손가락 페인팅 응용 프로그램을 만드는 것을 실험하고 있습니다. 화면 경로를 올바르게 그릴 수 있지만 모든 그려진 경로의 화면을 완전히 지울 수있는 옵션이 필요합니다. 현재 코드에서 컨텍스트를 지우지 만 드로잉 코드 블록을 호출하면 모든 경로가 화면에 다시 나타납니다.CGContextRef를 지우는 방법은 무엇입니까?

- (void)drawRect:(CGRect)rect 
{ 
    //Drawing code 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    if(clearContext == 0){ 

     CGContextSetLineWidth(context, 6); 
     CGContextSetRGBStrokeColor(context, 1, 0, 0, 1); 
     CGContextAddPath(context, drawingPath); 

     CGContextStrokePath(context); 
    } 
    if(clearContext == 1){ 

     //This is the code I currently have to clear the context, it is clearly wrong 
     //Just used as experimentation. 

     CGContextSetBlendMode(context, kCGBlendModeClear); 
     CGContextAddPath(context, drawingPath); 
     CGContextStrokePath(context); 
     clearContext = 0; 

    } 

} 

답변

4

메신저 가정 drawingPath는 CGPath입니다 ... 당신은 그 CGPath을 삭제입니까? 그런 짓을, 문제 경로를 취소 할 작업에

의 원인이 될 수 있습니다

CGPathRelease(drawingPath); 
drawingPath = CGPathCreateMutable(); 
[self setNeedsDisplay]; 

당신이 일반적으로 수행 정상 도면을한다. 경로가 비어 있으면 아무 것도 그려지지 않습니다.

+0

완벽하게 작동합니다 ... 감사합니다! – Michael