#pragma mark - 創(chuàng)建長按按鈕
-?(void)longpress
{
UILongPressGestureRecognizer?*longpress?=?[[UILongPressGestureRecognizer?alloc]?initWithTarget:self?action:@selector(longpressAction:)];
longpress.minimumPressDuration?= 1;//長按最短時間
[self.bigImage?addGestureRecognizer:longpress];//將手勢添加到想要觸發(fā)的圖上
[longpress?release];
}
#pragma mark - 長按鈕響應(yīng)事件
-?(void)longpressAction:(UILongPressGestureRecognizer?*)longpress
{
UIAlertController?*alert?=?[UIAlertController?alertControllerWithTitle:nil?message:@"是否保存圖片到本地"?preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction?*canelAction?=?[UIAlertAction?actionWithTitle:@"取消"?style:UIAlertActionStyleCancel?handler:^(UIAlertAction?*?_Nonnull?action)?{
//?點擊取消按鈕執(zhí)行的代碼
}];
UIAlertAction?*okAction?=?[UIAlertAction?actionWithTitle:@"確定"?style:UIAlertActionStyleDefault?handler:^(UIAlertAction?*?_Nonnull?action)?{
//?點擊確定按鈕執(zhí)行的代碼
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];
}
}