Reputation: 987
I am using CoreGraphics to implement free hand drawing which is working fine for me and now I want to implement Undo feature for this drawing so that user can clear his last strok
Upvotes: 3
Views: 191
Reputation: 1415
I never used this but you can find over here to undo or clear last things
Upvotes: 0
Reputation: 1234
In your method:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if(imageView2.image != nil){
[pathArray addObject:imageView2.image];
}
}
And on undo button:
if([pathArray count]>0)
{
[pathArray removeLastObject];
if([pathArray count]==0)
{
imageView2.image = GlobalImage2;
}
else
{
imageView2.image=[pathArray objectAtIndex:[pathArray count]-1];
}
}
Retrive this image from array. I have used same code in my few apps. I hope it'll be useful for you.
Thanks,
Hemang.
Upvotes: 5
Reputation: 656
You should read about the Memento Pattern. Some links:
In time, sorry for not explaining it here. But there are tons of books and articles about it.
Upvotes: 1