Reputation: 622
I am working on a drawing app and I am able to draw with my finger touch. Now I am trying to implement clear, undo, and redo functionality.
In my view controller I have two IBAction methods for "clearAll" and "Undo". I have created a custom class called drawing.h and .m where I have written functions for handling touch events. Below are my functions.
The problem is undo and redo work but the last color select in all line in drawn in undo and redo.
Upvotes: 0
Views: 784
Reputation: 622
I Have Mistake In Touch End Method In Array Last Array Not Remove on last object
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UIGraphicsBeginImageContext(self.tempimage.bounds.size);
[self.tempimage.layer renderInContext:UIGraphicsGetCurrentContext()];
rawImage = UIGraphicsGetImageFromCurrentImageContext();
[self.tempimage.image drawInRect:CGRectMake(0, 0, tempimage.frame.size.width, tempimage.frame.size.height) blendMode:blendmode alpha:opacity];
UIGraphicsEndImageContext();
#if PUSHTOFILE
lineIndex++;
[self performSelectorInBackground:@selector(writeFilesBG)
withObject:nil];
#else
NSDictionary *lineInfo = [NSDictionary dictionaryWithObjectsAndKeys:rawImage, @"IMAGE",nil];
[pointsArray addObject:lineInfo];
UIBezierPath *_path=[pointsArray lastObject];
[_stack addObject:_path];
[pointsArray removeLastObject];
[self.tempimage setNeedsDisplay];
#endif
}
Upvotes: 1