From b95af34f354cf144c54ea6384ce256568da5b8ec Mon Sep 17 00:00:00 2001 From: longitachi Date: Mon, 9 Oct 2017 10:15:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BD=91=E7=BB=9C=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E9=95=BF=E6=8C=89=E4=BF=9D=E5=AD=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PhotoBrowser/ZLBigImageCell.h | 4 +++ PhotoBrowser/ZLBigImageCell.m | 23 +++++++++++++++- PhotoBrowser/ZLPhotoActionSheet.h | 2 +- PhotoBrowser/ZLShowBigImgViewController.m | 26 +++++++++++++++++++ .../en.lproj/Localizable.strings | 1 - README.md | 4 +-- ZLPhotoBrowser.podspec | 4 +-- 7 files changed, 57 insertions(+), 7 deletions(-) diff --git a/PhotoBrowser/ZLBigImageCell.h b/PhotoBrowser/ZLBigImageCell.h index a29e299a..88c7542d 100644 --- a/PhotoBrowser/ZLBigImageCell.h +++ b/PhotoBrowser/ZLBigImageCell.h @@ -22,6 +22,7 @@ @property (nonatomic, strong) ZLPreviewView *previewView; @property (nonatomic, strong) ZLPhotoModel *model; @property (nonatomic, copy) void (^singleTapCallBack)(void); +@property (nonatomic, copy) void (^longPressCallBack)(void); @property (nonatomic, assign) BOOL willDisplaying; @@ -53,6 +54,7 @@ @property (nonatomic, strong) ZLPreviewVideo *videoView; @property (nonatomic, strong) ZLPhotoModel *model; @property (nonatomic, copy) void (^singleTapCallBack)(void); +@property (nonatomic, copy) void (^longPressCallBack)(void); /** 界面每次即将显示时,重置scrollview缩放状态 @@ -103,6 +105,8 @@ @property (nonatomic, strong) UIView *containerView; @property (nonatomic, strong) UIScrollView *scrollView; +@property (nonatomic, strong) UILongPressGestureRecognizer *longPressGesture; +@property (nonatomic, copy) void (^longPressCallBack)(void); - (void)loadGifImage:(PHAsset *)asset; - (void)loadImage:(id)obj; diff --git a/PhotoBrowser/ZLBigImageCell.m b/PhotoBrowser/ZLBigImageCell.m index ea3b0e91..b4fdffe1 100644 --- a/PhotoBrowser/ZLBigImageCell.m +++ b/PhotoBrowser/ZLBigImageCell.m @@ -45,6 +45,11 @@ - (instancetype)initWithFrame:(CGRect)frame strongify(weakSelf); if (strongSelf.singleTapCallBack) strongSelf.singleTapCallBack(); }; + self.previewView.longPressCallBack = ^{ + strongify(weakSelf); + if (strongSelf.longPressCallBack) + strongSelf.longPressCallBack(); + }; } return self; } @@ -102,6 +107,7 @@ - (ZLPreviewImageAndGif *)imageGifView if (!_imageGifView) { _imageGifView = [[ZLPreviewImageAndGif alloc] initWithFrame:self.bounds]; _imageGifView.singleTapCallBack = self.singleTapCallBack; + _imageGifView.longPressCallBack = self.longPressCallBack; } return _imageGifView; } @@ -216,7 +222,8 @@ - (void)resetScale - (UIImage *)image { - if (self.model.type == ZLAssetMediaTypeImage) { + if (self.model.type == ZLAssetMediaTypeImage || + self.model.type == ZLAssetMediaTypeNetImage) { return self.imageGifView.imageView.image; } return nil; @@ -437,6 +444,11 @@ - (void)loadNormalImage:(PHAsset *)asset */ - (void)loadImage:(id)obj { + if (!_longPressGesture) { + self.longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)]; + self.longPressGesture.minimumPressDuration = .5; + [self addGestureRecognizer:self.longPressGesture]; + } if ([obj isKindOfClass:UIImage.class]) { self.imageView.image = obj; [self resetSubviewSize:obj]; @@ -547,6 +559,15 @@ - (void)resetSubviewSize:(id)obj } #pragma mark - 手势点击事件 +- (void)longPressAction:(UILongPressGestureRecognizer *)ges +{ + if (ges.state == UIGestureRecognizerStateBegan) { + if (self.longPressCallBack) { + self.longPressCallBack(); + } + } +} + - (void)doubleTapAction:(UITapGestureRecognizer *)tap { UIScrollView *scrollView = self.scrollView; diff --git a/PhotoBrowser/ZLPhotoActionSheet.h b/PhotoBrowser/ZLPhotoActionSheet.h index 6c1bbe6d..ac632703 100644 --- a/PhotoBrowser/ZLPhotoActionSheet.h +++ b/PhotoBrowser/ZLPhotoActionSheet.h @@ -5,7 +5,7 @@ // Created by long on 15/11/25. // Copyright © 2015年 long. All rights reserved. // -//pods version 2.4.5 - 2017.9.28 update +//pods version 2.4.6 - 2017.10.9 update #import #import "ZLDefine.h" diff --git a/PhotoBrowser/ZLShowBigImgViewController.m b/PhotoBrowser/ZLShowBigImgViewController.m index 01082ce8..246b31a2 100644 --- a/PhotoBrowser/ZLShowBigImgViewController.m +++ b/PhotoBrowser/ZLShowBigImgViewController.m @@ -429,6 +429,28 @@ - (void)navRightBtn_Click:(UIButton *)btn [self resetEditBtnState]; } +- (void)showDownloadAlert +{ + UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertAction *save = [UIAlertAction actionWithTitle:GetLocalLanguageTextValue(ZLPhotoBrowserSaveText) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + ZLProgressHUD *hud = [[ZLProgressHUD alloc] init]; + [hud show]; + + ZLBigImageCell *cell = (ZLBigImageCell *)[_collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:_currentPage-1 inSection:0]]; + + [ZLPhotoManager saveImageToAblum:cell.previewView.image completion:^(BOOL suc, PHAsset *asset) { + [hud hide]; + if (!suc) { + ShowToastLong(@"%@", GetLocalLanguageTextValue(ZLPhotoBrowserSaveImageErrorText)); + } + }]; + }]; + UIAlertAction *cancel = [UIAlertAction actionWithTitle:GetLocalLanguageTextValue(ZLPhotoBrowserCancelText) style:UIAlertActionStyleCancel handler:nil]; + [alert addAction:save]; + [alert addAction:cancel]; + [self showDetailViewController:alert sender:nil]; +} + #pragma mark - 更新按钮、导航条等显示状态 - (void)resetDontBtnState { @@ -541,6 +563,10 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell strongify(weakSelf); [strongSelf handlerSingleTap]; }; + cell.longPressCallBack = ^{ + strongify(weakSelf); + [strongSelf showDownloadAlert]; + }; return cell; } diff --git a/PhotoBrowser/resource/ZLPhotoBrowser.bundle/en.lproj/Localizable.strings b/PhotoBrowser/resource/ZLPhotoBrowser.bundle/en.lproj/Localizable.strings index 6d7834dd..ed3e8899 100644 --- a/PhotoBrowser/resource/ZLPhotoBrowser.bundle/en.lproj/Localizable.strings +++ b/PhotoBrowser/resource/ZLPhotoBrowser.bundle/en.lproj/Localizable.strings @@ -37,4 +37,3 @@ "ZLPhotoBrowserLoadNetImageFailed" = "loading failed"; "ZLPhotoBrowserSaveVideoFailed" = "Failed to save the video"; - diff --git a/README.md b/README.md index 4b2762a5..d012b78e 100644 --- a/README.md +++ b/README.md @@ -31,18 +31,18 @@ - [x] 相册内拍照按钮实时显示镜头捕捉画面 - [x] 已选择图片遮罩层标记 - [x] 预览已选择照片 -- [x] 预览网络及本地照片 +- [x] 预览网络及本地照片(支持长按保存至相册) - [x] 相册内图片自定义圆角弧度 - [x] 自定义升序降序排列 - [x] 多张拍照 ### Feature -- [ ] 支持预览网络图片时长按下载 > 如果您在使用中有好的需求及建议,或者遇到什么bug,欢迎随时issue,我会及时的回复 ### 更新日志 ``` +● 2.4.6: 新增网络图片长按保存至相册功能 ● 2.4.3: 适配iPhone X,优化初次启动进入相册速度,预览网络图片可设置是否显示底部工具条及导航右侧按钮; ● 2.4.2: 新增编辑视频功能; ● 2.4.1: 新增仿iPhone相册滑动多选功能; diff --git a/ZLPhotoBrowser.podspec b/ZLPhotoBrowser.podspec index e6e001a2..9614185f 100644 --- a/ZLPhotoBrowser.podspec +++ b/ZLPhotoBrowser.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'ZLPhotoBrowser' - s.version = '2.4.5' - s.summary = 'A simple way to multiselect photos,video,gif,livephoto from ablum,force touch to preview image,support portrait and landscape,multiple languages(Chinese,English,Japanese)' + s.version = '2.4.6' + s.summary = 'A simple way to multiselect photos from ablum, force touch to preview photo, support portrait and landscape, edit photo, multiple languages(Chinese,English,Japanese)' s.homepage = 'https://github.com/longitachi/ZLPhotoBrowser' s.license = 'MIT' s.platform = :ios