- (void)saveImage
{
int index = _scrollView.contentOffset.x / _scrollView.bounds.size.width;
/*
为了支持gif图片的存储此处改动原第三方库的内容如下:
与原库比对可发现
原来的
*/
// UIImageView *currentImageView = _scrollView.subviews[index];
// UIImageWriteToSavedPhotosAlbum(currentImageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
NSURL * url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",[self highQualityImageURLForIndex:index]]];
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:url options:SDWebImageDownloaderUseNSURLCache progress:nil completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
if ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f) {
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
options.shouldMoveFile = YES;
[[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:data options:options];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
dispatch_sync(dispatch_get_main_queue(), ^{
//保存成功
// [self image:<#(UIImage *)#> didFinishSavingWithError:<#(NSError *)#> contextInfo:<#(void *)#>]
[self didFinishSavingWithError:error];
});
}];
}
else {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
dispatch_sync(dispatch_get_main_queue(), ^{
//保存成功
[self didFinishSavingWithError:error];
});
}];
}
}];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] init];
indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
indicator.center = self.center;
_indicatorView = indicator;
[[UIApplication sharedApplication].keyWindow addSubview:indicator];
[indicator startAnimating];
}
//保存结果提示语的出现以及indicator的消失
- (void)didFinishSavingWithError:(NSError *)error;
{
[_indicatorView removeFromSuperview];
UILabel *label = [[UILabel alloc] init];
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor colorWithRed:0.1f green:0.1f blue:0.1f alpha:0.90f];
label.layer.cornerRadius = 5;
label.clipsToBounds = YES;
label.bounds = CGRectMake(0, 0, 150, 30);
label.center = self.center;
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont boldSystemFontOfSize:17];
[[UIApplication sharedApplication].keyWindow addSubview:label];
[[UIApplication sharedApplication].keyWindow bringSubviewToFront:label];
if (error) {
label.text = SDPhotoBrowserSaveImageFailText;
} else {
label.text = SDPhotoBrowserSaveImageSuccessText;
}
[label performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.0];
}