Skip to content

Commit

Permalink
删除废弃文件,新增已选择图片遮罩层标记功能
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Sep 1, 2017
1 parent 992e233 commit 868ac0b
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 809 deletions.
6 changes: 3 additions & 3 deletions PhotoBrowser/ZLCollectionCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
@property (nonatomic, strong) UIImageView *videoImageView;
@property (nonatomic, strong) UIImageView *liveImageView;
@property (nonatomic, strong) UILabel *timeLabel;
//@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIView *topView;

@property (nonatomic, assign) BOOL allSelectGif;
@property (nonatomic, assign) BOOL allSelectLivePhoto;
@property (nonatomic, assign) BOOL showSelectBtn;
@property (nonatomic, assign) CGFloat cornerRadio;
@property (nonatomic, strong) ZLPhotoModel *model;
@property (nonatomic, strong) UIColor *maskColor;
@property (nonatomic, assign) BOOL showMask;

@property (nonatomic, copy) void (^selectedBlock)(BOOL);

@property (nonatomic, copy) BOOL (^isSelectedImage)();

@end


Expand Down
43 changes: 19 additions & 24 deletions PhotoBrowser/ZLCollectionCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ - (void)layoutSubviews
[super layoutSubviews];
self.imageView.frame = self.bounds;
self.btnSelect.frame = CGRectMake(GetViewWidth(self.contentView)-26, 5, 23, 23);
// self.topView.frame = self.bounds;
if (self.showMask) {
self.topView.frame = self.bounds;
}
self.videoBottomView.frame = CGRectMake(0, GetViewHeight(self)-15, GetViewWidth(self), 15);
self.videoImageView.frame = CGRectMake(5, 1, 16, 12);
self.liveImageView.frame = CGRectMake(5, -1, 15, 15);
Expand All @@ -49,6 +51,7 @@ - (UIImageView *)imageView
_imageView.clipsToBounds = YES;
[self.contentView addSubview:_imageView];

[self.contentView bringSubviewToFront:_topView];
[self.contentView bringSubviewToFront:self.videoBottomView];
[self.contentView bringSubviewToFront:self.btnSelect];
}
Expand Down Expand Up @@ -112,19 +115,16 @@ - (UILabel *)timeLabel
return _timeLabel;
}

//- (UIView *)topView
//{
// if (!_topView) {
// _topView = [[UIView alloc] init];
// _topView.backgroundColor = [UIColor whiteColor];
// _topView.alpha = 0.5;
// _topView.userInteractionEnabled = NO;
// _topView.hidden = YES;
// [self.contentView addSubview:_topView];
// [self.contentView bringSubviewToFront:_topView];
// }
// return _topView;
//}
- (UIView *)topView
{
if (!_topView) {
_topView = [[UIView alloc] init];
_topView.userInteractionEnabled = NO;
_topView.hidden = YES;
[self.contentView addSubview:_topView];
}
return _topView;
}

- (void)setModel:(ZLPhotoModel *)model
{
Expand All @@ -140,28 +140,23 @@ - (void)setModel:(ZLPhotoModel *)model
self.videoImageView.hidden = NO;
self.liveImageView.hidden = YES;
self.timeLabel.text = model.duration;
// if (self.isSelectedImage) {
// self.topView.hidden = !self.isSelectedImage();
// }
} else if (model.type == ZLAssetMediaTypeGif) {
self.videoBottomView.hidden = !self.allSelectGif;
self.videoImageView.hidden = YES;
self.liveImageView.hidden = YES;
self.timeLabel.text = @"GIF";
// if (self.allSelectGif && self.isSelectedImage) {
// self.topView.hidden = self.allSelectGif && !self.isSelectedImage();
// }
} else if (model.type == ZLAssetMediaTypeLivePhoto) {
self.videoBottomView.hidden = !self.allSelectLivePhoto;
self.videoImageView.hidden = YES;
self.liveImageView.hidden = NO;
self.timeLabel.text = @"Live";
// if (self.allSelectLivePhoto && self.isSelectedImage) {
// self.topView.hidden = self.allSelectLivePhoto && !self.isSelectedImage();
// }
} else {
self.videoBottomView.hidden = YES;
// self.topView.hidden = YES;
}

if (self.showMask) {
self.topView.backgroundColor = [self.maskColor colorWithAlphaComponent:.2];
self.topView.hidden = !model.isSelected;
}

self.btnSelect.hidden = !self.showSelectBtn;
Expand Down
2 changes: 1 addition & 1 deletion PhotoBrowser/ZLDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static inline NSInteger GetDuration (NSString *duration) {


static inline NSDictionary *
GetCustomRatio() {
GetCustomClipRatio() {
return @{ClippingRatioValue1: @(0), ClippingRatioValue2: @(0), ClippingRatioTitleFormat: @"Custom"};
}

Expand Down
18 changes: 9 additions & 9 deletions PhotoBrowser/ZLPhotoActionSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ NS_ASSUME_NONNULL_BEGIN
/**导航条颜色,默认 rgb(19, 153, 231)*/
@property (nonatomic, strong) UIColor *navBarColor;

/**选择照片回调,回调解析好的图片、对应的asset对象、是否原图*/
@property (nonatomic, copy) void (^selectImageBlock)(NSArray<UIImage *> *images, NSArray<PHAsset *> *assets, BOOL isOriginal);

/**选择gif照片回调,回调解析好的gif图片、对应的asset对象*/
@property (nonatomic, copy) void (^selectGifBlock)(UIImage *gif, PHAsset *asset) NS_DEPRECATED_IOS(2_0, 8_0, "pod 2.2.6版本之后已废弃,删除使用的地方即可, 统一通过selectImageBlock回调,后续将删除");
/**是否在已选择的图片上方覆盖一层已选中遮罩层,默认 NO*/
@property (nonatomic, assign) BOOL showSelectedMask;

/**选择live photo照片回调,回调解析好的live photo图片、对应的asset对象*/
@property (nonatomic, copy) void (^selectLivePhotoBlock)(UIImage *livePhoto, PHAsset *asset) NS_DEPRECATED_IOS(2_0, 8_0, "pod 2.2.6版本之后已废弃,删除使用的地方即可, 统一通过selectImageBlock回调,后续将删除");
/**遮罩层颜色,内部会默认调整颜色的透明度为0.2, 默认 blackColor*/
@property (nonatomic, strong) UIColor *selectedMaskColor;

/**选择视频回调,回调第一帧封面图片、对应的asset对象*/
@property (nonatomic, copy) void (^selectVideoBlock)(UIImage *cover, PHAsset *asset) NS_DEPRECATED_IOS(2_0, 8_0, "pod 2.2.6版本之后已废弃,删除使用的地方即可, 统一通过selectImageBlock回调,后续将删除");
/**
选择照片回调,回调解析好的图片、对应的asset对象、是否原图
pod 2.2.6版本之后 统一通过selectImageBlock回调
*/
@property (nonatomic, copy) void (^selectImageBlock)(NSArray<UIImage *> *images, NSArray<PHAsset *> *assets, BOOL isOriginal);

- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;

Expand Down
49 changes: 11 additions & 38 deletions PhotoBrowser/ZLPhotoActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#import "ZLThumbnailViewController.h"
#import "ZLNoAuthorityViewController.h"
#import "ToastUtils.h"
#import "ZLShowGifViewController.h"
#import "ZLShowVideoViewController.h"
#import "ZLShowLivePhotoViewController.h"
#import "ZLEditViewController.h"

#define kBaseViewHeight (self.maxPreviewCount ? 300 : 142)
Expand Down Expand Up @@ -93,10 +90,6 @@ - (void)setArrSelectedAssets:(NSMutableArray<PHAsset *> *)arrSelectedAssets
_arrSelectedAssets = arrSelectedAssets;
[self.arrSelectedModels removeAllObjects];
for (PHAsset *asset in arrSelectedAssets) {
// if (asset.mediaType != PHAssetMediaTypeImage) {
// //选择的视频不做保存
// continue;
// }
ZLPhotoModel *model = [ZLPhotoModel modelWithAsset:asset type:[ZLPhotoManager transformAssetType:asset] duration:nil];
model.isSelected = YES;
[self.arrSelectedModels addObject:model];
Expand Down Expand Up @@ -140,6 +133,8 @@ - (instancetype)init
self.showCaptureImageOnTakePhotoBtn = YES;
self.sortAscending = YES;
self.showSelectBtn = NO;
self.showSelectedMask = NO;
self.selectedMaskColor = [UIColor blackColor];

if (![self judgeIsHavePhotoAblumAuthority]) {
//注册实施监听相册变化
Expand Down Expand Up @@ -300,8 +295,7 @@ - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message
- (void)loadPhotoFromAlbum
{
[self.arrDataSources removeAllObjects];
//因为预览界面需快速选择最近图片,所以不受self.sortAscending限制,
//这里allow gif和allow liveohoto 置为yes,为了获取所有asset

[self.arrDataSources addObjectsFromArray:[ZLPhotoManager getAllAssetInPhotoAlbumWithAscending:NO limitCount:self.maxPreviewCount allowSelectVideo:self.allowSelectVideo allowSelectImage:self.allowSelectImage allowSelectGif:self.allowSelectGif allowSelectLivePhoto:self.allowSelectLivePhoto]];
[ZLPhotoManager markSelcectModelInArr:self.arrDataSources selArr:self.arrSelectedModels];
[self.collectionView reloadData];
Expand Down Expand Up @@ -534,18 +528,19 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
}
}
}

if (strongSelf.showSelectedMask) {
strongCell.topView.hidden = !model.isSelected;
}
[strongSelf changeCancelBtnTitle];
// [collectionView reloadItemsAtIndexPaths:[collectionView indexPathsForVisibleItems]];
};

cell.isSelectedImage = ^BOOL() {
strongify(weakSelf);
return strongSelf.arrSelectedModels.count > 0;
};
cell.allSelectGif = self.allowSelectGif;
cell.allSelectLivePhoto = self.allowSelectLivePhoto;
cell.showSelectBtn = self.showSelectBtn;
cell.cornerRadio = self.cellCornerRadio;
cell.showMask = self.showSelectedMask;
cell.maskColor = self.selectedMaskColor;
cell.model = model;

return cell;
Expand Down Expand Up @@ -659,6 +654,8 @@ - (ZLImageNavigationController *)getImageNavWithRootVC:(UIViewController *)rootV
nav.showSelectBtn = self.showSelectBtn;
nav.isSelectOriginalPhoto = self.isSelectOriginalPhoto;
nav.navBarColor = self.navBarColor;
nav.showSelectedMask = self.showSelectedMask;
nav.selectedMaskColor = self.selectedMaskColor;
[nav.arrSelectedModels removeAllObjects];
[nav.arrSelectedModels addObjectsFromArray:self.arrSelectedModels];

Expand Down Expand Up @@ -708,30 +705,6 @@ - (void)pushEditVCWithModel:(ZLPhotoModel *)model
[self.sender showDetailViewController:nav sender:nil];
}

- (void)pushGifViewControllerWithModel:(ZLPhotoModel *)model
{
ZLShowGifViewController *vc = [[ZLShowGifViewController alloc] init];
vc.model = model;
ZLImageNavigationController *nav = [self getImageNavWithRootVC:vc];
[self.sender showDetailViewController:nav sender:nil];
}

- (void)pushLivePhotoViewControllerWithModel:(ZLPhotoModel *)model
{
ZLShowLivePhotoViewController *vc = [[ZLShowLivePhotoViewController alloc] init];
vc.model = model;
ZLImageNavigationController *nav = [self getImageNavWithRootVC:vc];
[self.sender showDetailViewController:nav sender:nil];
}

- (void)pushVideoViewControllerWithModel:(ZLPhotoModel *)model
{
ZLShowVideoViewController *vc = [[ZLShowVideoViewController alloc] init];
vc.model = model;
ZLImageNavigationController *nav = [self getImageNavWithRootVC:vc];
[self.sender showDetailViewController:nav sender:nil];
}

#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
Expand Down
6 changes: 6 additions & 0 deletions PhotoBrowser/ZLPhotoBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
/**导航条颜色,默认 rgb(19, 153, 231)*/
@property (nonatomic, strong) UIColor *navBarColor;

/**是否在已选择的图片上方覆盖一层已选中遮罩层,默认 NO*/
@property (nonatomic, assign) BOOL showSelectedMask;

/**遮罩层颜色,内部会默认调整颜色的透明度为0.2, 默认 blackColor*/
@property (nonatomic, strong) UIColor *selectedMaskColor;

/**点击确定选择照片回调*/
@property (nonatomic, copy) void (^callSelectImageBlock)();

Expand Down
12 changes: 5 additions & 7 deletions PhotoBrowser/ZLPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,11 @@ - (UIImage *)imageWithColor:(UIColor*)color
if (_clipRatios) {
return _clipRatios;
} else {
return @[
@{ClippingRatioValue1: @0, ClippingRatioValue2: @0, ClippingRatioTitleFormat: @"Custom"},
@{ClippingRatioValue1: @1, ClippingRatioValue2: @1, ClippingRatioTitleFormat: @"%g : %g"},
@{ClippingRatioValue1: @4, ClippingRatioValue2: @3, ClippingRatioTitleFormat: @"%g : %g"},
@{ClippingRatioValue1: @3, ClippingRatioValue2: @2, ClippingRatioTitleFormat: @"%g : %g"},
@{ClippingRatioValue1: @16, ClippingRatioValue2: @9, ClippingRatioTitleFormat: @"%g : %g"},
];
return @[GetCustomClipRatio(),
GetClipRatio(1, 1),
GetClipRatio(4, 3),
GetClipRatio(3, 2),
GetClipRatio(16, 9)];
}
}

Expand Down
17 changes: 0 additions & 17 deletions PhotoBrowser/ZLShowGifViewController.h

This file was deleted.

Loading

0 comments on commit 868ac0b

Please sign in to comment.