1、 UIImageView的監(jiān)聽(tīng)方法
2、 如何將圖片保存到本地相冊(cè)
3、 SDWebImage的常用方法
一、在很多時(shí)候,UIImageView都有與用戶(hù)進(jìn)行交互,但它和UIButton不同, 在不設(shè)置的情況下,點(diǎn)擊圖片是不可以監(jiān)聽(tīng)的 , 下面是兩個(gè)要點(diǎn)
// 圖片點(diǎn)擊
// 開(kāi)啟用戶(hù)交互
self.imageView.userInteractionEnabled = YES;
// 添加手勢(shì)識(shí)別器
[self.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showPicture)]];
二、將圖片保存到本地, 用UIImageWriteToSavedPhotosAlbum方法
// 保存
- (IBAction)saveAction {
if (self.imageView.image == nil) {
[SVProgressHUD showErrorWithStatus:@"圖片并沒(méi)有下載完畢"];
return;
}
// 保存圖片到本地, 要用下面的那個(gè)方法
UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
// 存儲(chǔ)圖片
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
if (error) {
[SVProgressHUD showErrorWithStatus:@"保存失敗!"];
} else {
[SVProgressHUD showSuccessWithStatus:@"保存成功!"];
}
}
三、SDWebImage 監(jiān)聽(tīng)圖片下載, 在使用SDWebImage的時(shí)候,要設(shè)置是否明文

Snip20160526_1.png
[imageView sd_setImageWithURL:[NSURL URLWithString:self.topic.large_image] placeholderImage:nil options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
self.progressView.hidden = NO;
[self.progressView setProgress:1.0 * receivedSize / expectedSize animated:YES];
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
self.progressView.hidden = YES;
}];