需要引两个第三方文件
#import"UIImageView+WebCache.h"
#import"UIImage+GIF.h"
// [self.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://v.juhe.cn/movie/picurl?2583181"]];
// self.imageView.image = [UIImage sd_animatedGIFNamed:@"动态图"];//可以显示动态图
//创建一个
UIActionSheet*sheet = [[UIActionSheetalloc]initWithTitle:@"选择图像"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"从相册选取",nil];
[sheetshowInView:self.view];
self.imageView.userInteractionEnabled=YES;
UILongPressGestureRecognizer*longPress = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(longPress:)];
[self.imageViewaddGestureRecognizer:longPress];
}
- (void)longPress:(UILongPressGestureRecognizer*)longPress{
// NSLog(@"测试");
//判断手势刚开始
if(longPress.state==UIGestureRecognizerStateBegan) {
UIImageWriteToSavedPhotosAlbum(self.imageView.image,nil,nil,nil);//将图片吸入本地相册中
}
}
- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex ==0) {
UIImagePickerController*picker = [[UIImagePickerControlleralloc]init];
//设置代理人
//这个地方很特殊,这个代理人执行两套协议,需要签订两个协议
picker.delegate=self;
picker.allowsEditing=YES;
//让他显示出来,用模态
[selfpresentViewController:pickeranimated:YEScompletion:^{
}];
}
}
#pragma mark -点击choose之后,可以选中当前的图片,并且返回让图片显示在imageView上
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{
//隐藏的效果就取消了,所以,我们需要手动添加dismiss的方法
[selfdismissViewControllerAnimated:YEScompletion:^{
} ];
NSLog(@"%@", info);
//从返回的字典对象info中提取image
UIImage*image = info[UIImagePickerControllerEditedImage];
self.imageView.image= image;
}