相册新增保存gif图片功能
This commit is contained in:
@@ -11,12 +11,11 @@
|
|||||||
#import "SDBrowserImageView.h"
|
#import "SDBrowserImageView.h"
|
||||||
#import <SDWebImageFLPlugin/SDWebImageFLPlugin.h>
|
#import <SDWebImageFLPlugin/SDWebImageFLPlugin.h>
|
||||||
#import <AssetsLibrary/AssetsLibrary.h>
|
#import <AssetsLibrary/AssetsLibrary.h>
|
||||||
#import <MobileCoreServices/MobileCoreServices.h>
|
#import <Photos/Photos.h>
|
||||||
#import <PhotosUI/PhotosUI.h>
|
|
||||||
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO) //判断是否iPhoneX
|
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO) //判断是否iPhoneX
|
||||||
|
|
||||||
#define iPhoneX_NavSafeArea ([[UIScreen mainScreen] bounds].size.height >= 812.0 ? 24 : 0) // 如果是iphoneX 顶部安全区域 24
|
#define iPhoneX_NavSafeArea ([[UIScreen mainScreen] bounds].size.height >= 812.0 ? 24 : 0) // 如果是iphoneX 顶部安全区域 24
|
||||||
|
|
||||||
// ============在这里方便配置样式相关设置===========
|
// ============在这里方便配置样式相关设置===========
|
||||||
|
|
||||||
// ||
|
// ||
|
||||||
@@ -99,18 +98,21 @@
|
|||||||
{
|
{
|
||||||
int index = _scrollView.contentOffset.x / _scrollView.bounds.size.width;
|
int index = _scrollView.contentOffset.x / _scrollView.bounds.size.width;
|
||||||
FLAnimatedImageView *currentImageView = _scrollView.subviews[index];
|
FLAnimatedImageView *currentImageView = _scrollView.subviews[index];
|
||||||
BOOL isGif = [UIImage isGifWithImageData:currentImageView.animatedImage.data];
|
NSData *imageData = currentImageView.animatedImage.data;
|
||||||
if(isGif){
|
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
|
||||||
ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
|
if(imageData != nil){
|
||||||
NSDictionary *metadate = @{@"UTI":(__bridge NSString *)kUTTypeGIF};
|
[PHAssetCreationRequest.creationRequestForAsset addResourceWithType:PHAssetResourceTypePhoto data:imageData options:nil];
|
||||||
[library writeImageDataToSavedPhotosAlbum:currentImageView.animatedImage.data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
|
}else{
|
||||||
|
[PHAssetCreationRequest creationRequestForAssetFromImage:currentImageView.image];
|
||||||
|
}
|
||||||
|
} completionHandler:^(BOOL success, NSError * _Nullable error) {
|
||||||
|
//保存之后需要做的事情
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
// 需要在主线程执行的代码
|
||||||
[self saveImageFinishWithError:error];
|
[self saveImageFinishWithError:error];
|
||||||
}];
|
});
|
||||||
}else{
|
|
||||||
UIImageWriteToSavedPhotosAlbum(currentImageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
|
}];
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (_indicatorView == nil) {
|
if (_indicatorView == nil) {
|
||||||
_indicatorView = [[UIActivityIndicatorView alloc] init];
|
_indicatorView = [[UIActivityIndicatorView alloc] init];
|
||||||
_indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
|
_indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
|
||||||
@@ -141,28 +143,7 @@
|
|||||||
}
|
}
|
||||||
[label performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.0];
|
[label performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.0];
|
||||||
}
|
}
|
||||||
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;
|
|
||||||
{
|
|
||||||
[_indicatorView stopAnimating];
|
|
||||||
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setupScrollView
|
- (void)setupScrollView
|
||||||
{
|
{
|
||||||
@@ -176,7 +157,7 @@
|
|||||||
for (int i = 0; i < self.imageCount; i++) {
|
for (int i = 0; i < self.imageCount; i++) {
|
||||||
SDBrowserImageView *imageView = [[SDBrowserImageView alloc] init];
|
SDBrowserImageView *imageView = [[SDBrowserImageView alloc] init];
|
||||||
imageView.tag = i;
|
imageView.tag = i;
|
||||||
|
|
||||||
// 单击图片
|
// 单击图片
|
||||||
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(photoClick:)];
|
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(photoClick:)];
|
||||||
|
|
||||||
@@ -231,7 +212,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CGRect targetTemp = (!CGRectEqualToRect(self.sourceImagesFrame, CGRectZero)) ? self.sourceImagesFrame : [self.sourceImagesContainerView convertRect:sourceView.frame toView:self];
|
CGRect targetTemp = (!CGRectEqualToRect(self.sourceImagesFrame, CGRectZero)) ? self.sourceImagesFrame : [self.sourceImagesContainerView convertRect:sourceView.frame toView:self];
|
||||||
UIImageView *tempView = [[UIImageView alloc] init];
|
UIImageView *tempView = [[UIImageView alloc] init];
|
||||||
tempView.contentMode = sourceView.contentMode;
|
tempView.contentMode = sourceView.contentMode;
|
||||||
tempView.clipsToBounds = YES;
|
tempView.clipsToBounds = YES;
|
||||||
@@ -246,7 +227,7 @@
|
|||||||
tempView.center = self.center;
|
tempView.center = self.center;
|
||||||
|
|
||||||
[self addSubview:tempView];
|
[self addSubview:tempView];
|
||||||
|
|
||||||
_saveButton.hidden = YES;
|
_saveButton.hidden = YES;
|
||||||
|
|
||||||
[UIView animateWithDuration:SDPhotoBrowserHideImageAnimationDuration animations:^{
|
[UIView animateWithDuration:SDPhotoBrowserHideImageAnimationDuration animations:^{
|
||||||
@@ -269,7 +250,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDBrowserImageView *view = (SDBrowserImageView *)recognizer.view;
|
SDBrowserImageView *view = (SDBrowserImageView *)recognizer.view;
|
||||||
|
|
||||||
[view doubleTapToZommWithScale:scale];
|
[view doubleTapToZommWithScale:scale];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,7 +318,7 @@
|
|||||||
sourceView = [view cellForItemAtIndexPath:path];
|
sourceView = [view cellForItemAtIndexPath:path];
|
||||||
} else {
|
} else {
|
||||||
NSIndexPath *path = [NSIndexPath indexPathForItem:self.currentImageIndex inSection:0];
|
NSIndexPath *path = [NSIndexPath indexPathForItem:self.currentImageIndex inSection:0];
|
||||||
sourceView = [view cellForItemAtIndexPath:path];
|
sourceView = [view cellForItemAtIndexPath:path];
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
if (self.currentImageIndex<self.sourceImagesContainerView.subviews.count) {
|
if (self.currentImageIndex<self.sourceImagesContainerView.subviews.count) {
|
||||||
|
Reference in New Issue
Block a user