2014-02-26 95 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