Skip to content

Commit

Permalink
新增网络图片长按保存功能
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Oct 9, 2017
1 parent 1037e1f commit b95af34
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 7 deletions.
4 changes: 4 additions & 0 deletions PhotoBrowser/ZLBigImageCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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缩放状态
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 22 additions & 1 deletion PhotoBrowser/ZLBigImageCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -102,6 +107,7 @@ - (ZLPreviewImageAndGif *)imageGifView
if (!_imageGifView) {
_imageGifView = [[ZLPreviewImageAndGif alloc] initWithFrame:self.bounds];
_imageGifView.singleTapCallBack = self.singleTapCallBack;
_imageGifView.longPressCallBack = self.longPressCallBack;
}
return _imageGifView;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion PhotoBrowser/ZLPhotoActionSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <UIKit/UIKit.h>
#import "ZLDefine.h"
Expand Down
26 changes: 26 additions & 0 deletions PhotoBrowser/ZLShowBigImgViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -541,6 +563,10 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
strongify(weakSelf);
[strongSelf handlerSingleTap];
};
cell.longPressCallBack = ^{
strongify(weakSelf);
[strongSelf showDownloadAlert];
};

return cell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@

"ZLPhotoBrowserLoadNetImageFailed" = "loading failed";
"ZLPhotoBrowserSaveVideoFailed" = "Failed to save the video";

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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相册滑动多选功能;
Expand Down
4 changes: 2 additions & 2 deletions ZLPhotoBrowser.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b95af34

Please sign in to comment.