iOS中长按图片保存到本地
- (void)viewDidLoad {
[super viewDidLoad];
_testImageView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_testImageView.image = [UIImage imageNamed:@"test.jpg"];
_testImageView.userInteractionEnabled = YES;
[self.view addSubview:_testImageView];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressClicked:)];
[_testImageView addGestureRecognizer:longPress];
}
- (void)longPressClicked:(UILongPressGestureRecognizer *)longPress {
NSLog(@"press");
UIImageWriteToSavedPhotosAlbum(_testImageView.image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
}
//实现imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:方法
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (!error) {
message = @"成功保存到相册";
}else
{
message = [error description];
}
NSLog(@"message is %@",message);
}