iOS实战iOS图片选择

iOS长按图片保存实现方法

2016-05-30  本文已影响2632人  轻斟浅醉17

1、添加手势识别:

   UITapGestureRecognizer*tap =   [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(imgTapCliclk:)];

   UILongPressGestureRecognizer*longTap = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(imglongTapClick:)];

2、imaglongTapClick:

 -(void)imglongTapClick:(UILongPressGestureRecognizer*)gesture

{

if(gesture.state==UIGestureRecognizerStateBegan)

{

UIActionSheet*actionSheet = [[UIActionSheetalloc]initWithTitle:@"保存图片"delegate:self cancelButtonTitle:@"取消"destructiveButtonTitle:nil otherButtonTitles:@"保存图片到手机",nil];

actionSheet.actionSheetStyle=UIActionSheetStyleBlackOpaque;

[actionSheetshowInView:self];

UIImageView*img = (UIImageView*)[gestureview];

_sentImg= img;

}

}

 - (void)actionSheet:(UIActionSheet*)actionSheet didDismissWithButtonIndex:  (NSInteger)buttonIndex

{

if(buttonIndex ==0) {
UIImageWriteToSavedPhotosAlbum(_sentImg.image,self,@selector(imageSavedToPhot  osAlbum:didFinishSavingWithError:contextInfo:),nil);

}

}

pragma mark --- UIActionSheetDelegate---

- (void)imageSavedToPhotosAlbum:(UIImage*)image didFinishSavingWithError:  (NSError*)error contextInfo:(void*)contextInfo

{

NSString*message =@"呵呵";

if(!error) {

message =@"成功保存到相册";

 UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:messagedelegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil];

[alertshow];

}else

{

message = [errordescription];

UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"提    示"message:messagedelegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil];

[alertshow];

}

}
上一篇 下一篇

猜你喜欢

热点阅读