如何在绘图中实现撤消功能,以便用户可以清除他的最后一行

vir*_*wal 3 iphone objective-c ios5 ios6

我正在使用CoreGraphics实现免费的手绘,这对我来说很好,现在我想为这个绘图实现撤消功能,以便用户可以清除他的最后一次

Hem*_*ang 5

在你的方法中:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    if(imageView2.image != nil){
        [pathArray addObject:imageView2.image];
    }

}
Run Code Online (Sandbox Code Playgroud)

并在撤消按钮上:

if([pathArray count]>0)
{
    [pathArray removeLastObject];
    if([pathArray count]==0)
    {
        imageView2.image = GlobalImage2;
    }
    else
    {
        imageView2.image=[pathArray objectAtIndex:[pathArray count]-1];
    }

}
Run Code Online (Sandbox Code Playgroud)

从数组中恢复此图像.我在我的几个应用程序中使用了相同的代码.我希望它对你有用.

谢谢,

Hemang.