#pragma mark - 创建长按按钮
- (void)longpress
{
UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longpressAction:)];
longpress.minimumPressDuration = 1;//长按最短时间
[self.bigImage addGestureRecognizer:longpress];//将手势添加到想要触发的图上
[longpress release];
}
#pragma mark - 长按钮响应事件
- (void)longpressAction:(UILongPressGestureRecognizer *)longpress
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"是否保存图片到本地" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *canelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// 点击取消按钮执行的代码
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// 点击确定按钮执行的代码
UIImageWriteToSavedPhotosAlbum(self.bigImage.image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);//将图片写入本地
}];
[alert addAction:canelAction];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
}
#pragma mark - 成功保存图片
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
NSString *message = @"";
if (!error) {
message = @"成功保存到相册";
}else
{
message = [error description];
}
}