我在iOS設備進行繪圖工作,我有我的代碼工作,繪圖工作正常,現在我已經實現了撤銷和重做功能,但正在發生的事情是,假設我得出兩點線,然後按撤消按鈕,然後第一條線繪製得到模糊,,我不明白爲什麼發生,下面是我的撤消代碼。獲得,而在iOS的
-
(void)redrawLine
{
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
NSDictionary *lineInfo = [lineArray lastObject];
curImage = (UIImage*)[lineInfo valueForKey:@"IMAGE"];
UIGraphicsEndImageContext();
[self setNeedsDisplayInRect:self.bounds];
[self setNeedsDisplay];
}
-(void)undoButtonClicked
{
if([lineArray count]>0){
NSMutableArray *_line=[lineArray lastObject];
[bufferArray addObject:[_line copy]];
[lineArray removeLastObject];
drawStep = UNDO;
[self redrawLine];
}
}
- (void)drawRect:(CGRect)rect
{
switch (drawStep) {
case DRAW:
{
[curImage drawAtPoint:CGPointMake(0, 0)];
CGPoint mid1 = midPoint(previousPoint1, previousPoint2);
CGPoint mid2 = midPoint(currentPoint, previousPoint1);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];
CGContextMoveToPoint(context, mid1.x, mid1.y);
CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
CGContextSetLineCap(context, kCGLineCapButt);
CGContextSetLineWidth(context, self.lineWidth);
CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
CGContextSetAlpha(context, self.lineAlpha);
CGContextSetAllowsAntialiasing(context, YES);
CGContextStrokePath(context);
[super drawRect:rect];
}
case UNDO:
{
[curImage drawInRect:self.bounds];
break;
}
}
下面是當按下復原按鈕,發生了什麼圖像
第一個圖像是在點擊之前undobutton和第二圖像是在點擊undobutton後
關注 Ranji t
朋友你好,有任何意見 – Ranjit 2012-07-13 08:46:24