diff --git a/xplan-ios/Base/Tool/SDPhotoBrowser/SDPhotoBrowser.m b/xplan-ios/Base/Tool/SDPhotoBrowser/SDPhotoBrowser.m index 1beafda3..d351e118 100755 --- a/xplan-ios/Base/Tool/SDPhotoBrowser/SDPhotoBrowser.m +++ b/xplan-ios/Base/Tool/SDPhotoBrowser/SDPhotoBrowser.m @@ -11,12 +11,11 @@ #import "SDBrowserImageView.h" #import #import -#import -#import +#import #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 - + // ============在这里方便配置样式相关设置=========== // || @@ -99,18 +98,21 @@ { int index = _scrollView.contentOffset.x / _scrollView.bounds.size.width; FLAnimatedImageView *currentImageView = _scrollView.subviews[index]; - BOOL isGif = [UIImage isGifWithImageData:currentImageView.animatedImage.data]; - if(isGif){ - ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init]; - NSDictionary *metadate = @{@"UTI":(__bridge NSString *)kUTTypeGIF}; -  [library writeImageDataToSavedPhotosAlbum:currentImageView.animatedImage.data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) { + NSData *imageData = currentImageView.animatedImage.data; + [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ + if(imageData != nil){ + [PHAssetCreationRequest.creationRequestForAsset addResourceWithType:PHAssetResourceTypePhoto data:imageData options:nil]; + }else{ + [PHAssetCreationRequest creationRequestForAssetFromImage:currentImageView.image]; + } + } completionHandler:^(BOOL success, NSError * _Nullable error) { + //保存之后需要做的事情 + dispatch_async(dispatch_get_main_queue(), ^{ + // 需要在主线程执行的代码 [self saveImageFinishWithError:error]; - }]; - }else{ - UIImageWriteToSavedPhotosAlbum(currentImageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); - } - - + }); + + }]; if (_indicatorView == nil) { _indicatorView = [[UIActivityIndicatorView alloc] init]; _indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; @@ -141,28 +143,7 @@ } [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 { @@ -176,7 +157,7 @@ for (int i = 0; i < self.imageCount; i++) { SDBrowserImageView *imageView = [[SDBrowserImageView alloc] init]; imageView.tag = i; - + // 单击图片 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]; tempView.contentMode = sourceView.contentMode; tempView.clipsToBounds = YES; @@ -246,7 +227,7 @@ tempView.center = self.center; [self addSubview:tempView]; - + _saveButton.hidden = YES; [UIView animateWithDuration:SDPhotoBrowserHideImageAnimationDuration animations:^{ @@ -269,7 +250,7 @@ } SDBrowserImageView *view = (SDBrowserImageView *)recognizer.view; - + [view doubleTapToZommWithScale:scale]; } @@ -337,7 +318,7 @@ sourceView = [view cellForItemAtIndexPath:path]; } else { NSIndexPath *path = [NSIndexPath indexPathForItem:self.currentImageIndex inSection:0]; - sourceView = [view cellForItemAtIndexPath:path]; + sourceView = [view cellForItemAtIndexPath:path]; } }else { if (self.currentImageIndex