2014-02-26 144 views
0
繪圖

我在繪圖應用程序的工作,我有一個UIBezeirPath,與我在touchesMoved畫,並將其轉換爲CGPath,然後畫上CGlayer,橡皮擦iOS中

這裏是我的代碼

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
    { 
       self.currentPath = [[DrawingPath alloc] init]; 

       if(m_eraseButtonClicked) 
       { 
        [self.currentPath setPathColor:[UIColor backgroundColor]];    
       } 
       else 
       { 
        [self.currentPath setPathColor:self.lineColor]; 
       } 
      CGPathRef cgPath = self.currentPath.path.CGPath; 
      mutablePath = CGPathCreateMutableCopy(cgPath); 
    } 


- (void)Erase 
{ 
    CGContextRef layerContext = CGLayerGetContext(self.DrawingLayer);    

    CGContextSetBlendMode(layerContext,kCGBlendModeClear); 
    CGContextSetLineWidth(layerContext, self.eraseWidth); 
    CGContextBeginPath(layerContext); 
    CGContextAddPath(layerContext, mutablePath); 
    CGContextStrokePath(layerContext); 
} 

- (void)UndoRedoFunction 
{ 
//Undo/Redo 

    for(int i =0; i<[undoArray count];i++) 
    { 
     DrawingPath *drawPath = [undoArray objectAtIndex:i]; 
     CGPathRef path = drawPath.path.CGPath; 
     mutablePath = CGPathCreateMutableCopy(path); 


     CGContextBeginPath(layerContext); 
     CGContextAddPath(layerContext, mutablePath); 
     CGContextSetLineWidth(layerContext, drawPath.pathWidth.floatValue); 
     CGContextSetStrokeColorWithColor(layerContext, drawPath.pathColor.CGColor); 
     CGContextSetFillColorWithColor(layerContext, drawPath.pathColor.CGColor); 
     CGContextSetBlendMode(layerContext,kCGBlendModeNormal); 
     CGContextStrokePath(layerContext); 
     CGPathRelease(mutablePath);     
    } 
} 

擦除工作得很好,因爲我用的BlendMode清除,但當撤銷/重做,你可以看到,我從路徑和中風它與blenModeNormal的pathColor,我看到的白線,

下面是圖像,我寫 - >擦除 - >撤消 - >重做

enter image description here

回答

0

您是否正確粘貼了您的代碼?如上所示,-touchesMoved:withEvent方法在第14行附近關閉,在//Erase語句之前。這意味着你的CGContextRef現在是一個類變量,你的for循環從來不會被任何人執行,我不認爲它會編譯,因此我不知道你是否省略了一些代碼。

+0

我已更新它,請現在檢查 – Ranjit