我将创建一个撤消按钮,它会重置原始图片(加载保存的图像)。 但是,如果按下撤消按钮,则会隐藏整个图像视图。
我希望有人可以帮助我。
这是我的代码:
- (IBAction)undo:(id)sender
{
NSString *cachedFolderPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
NSString *cachedImagePath = [cachedFolderPath stringByAppendingPathComponent:@"image.png"];
UIImage *image1 = [UIImage imageWithData:[NSData dataWithContentsOfFile:cachedImagePath]];
[self->imgView setImage:image1];
}
- (void)saveImage: (UIImage*)image
{
UIImage *image1 = imgView.image;
NSString *cachedFolderPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
NSString *cachedImagePath = [cachedFolderPath stringByAppendingPathComponent:@"image.png"];
[UIImagePNGRepresentation(image1) writeToFile:cachedImagePath atomically:YES];
}
调试:
首先(UIImage(image1)不是)
第二个(UIImage(image1)是零,但我不知道为什么):