一、添加手勢識別:spa
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imgTapCliclk:)];圖片
UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(imglongTapClick:)];ip
二、imaglongTapClick:get
-(void)imglongTapClick:(UILongPressGestureRecognizer *)gestureit
{io
if(gesture.state == UIGestureRecognizerStateBegan)class
{select
UIActionSheet *actionSheet = [[UIActionSheet alloc]im
initWithTitle:@"保存圖片"error
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"保存圖片到手機",nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self];
UIImageView *img = (UIImageView *)[gesture view];
_sentImg = img;
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
UIImageWriteToSavedPhotosAlbum(_sentImg.image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
}
}
#pragma mark --- UIActionSheetDelegate---
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
NSString *message = @"呵呵";
if (!error) {
message = @"成功保存到相冊";
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"肯定" otherButtonTitles: nil];
[alert show];
}else
{
message = [error description];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"肯定" otherButtonTitles: nil];
[alert show];
}
}