Skip to content

Commit

Permalink
1.抽取相册属性独立为 ZLPhotoConfiguration 对象
Browse files Browse the repository at this point in the history
2.新增设置状态栏样式的api
3.优化部分代码,解决预览已选择图片和网络图片时候内存泄漏的地方
  • Loading branch information
longitachi committed Nov 20, 2017
1 parent 2a1dc97 commit c39d36d
Show file tree
Hide file tree
Showing 20 changed files with 700 additions and 753 deletions.
1 change: 1 addition & 0 deletions PhotoBrowser/NSBundle+ZLPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "NSBundle+ZLPhotoBrowser.h"
#import "ZLPhotoActionSheet.h"
#import "ZLDefine.h"

@implementation NSBundle (ZLPhotoBrowser)

Expand Down
2 changes: 1 addition & 1 deletion PhotoBrowser/ZLCustomCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ - (void)dealloc

[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self];
// NSLog(@"%s", __func__);
// NSLog(@"---- %s", __FUNCTION__);
}

- (void)viewDidLoad {
Expand Down
7 changes: 0 additions & 7 deletions PhotoBrowser/ZLDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@

#define kRGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]

#define kNavBar_color kRGB(19, 153, 231)
#define kNavBar_tintColor kRGB(255, 255, 255)
#define kBottomViewBgColor kRGB(255, 255, 255)
#define kDoneButton_textColor kRGB(255, 255, 255)
#define kBottomBtnsNormalTitleColor kRGB(80, 180, 234)
#define kBottomBtnsDisableTitleColor kRGB(200, 200, 200)

#define zl_weakify(var) __weak typeof(var) weakSelf = var
#define zl_strongify(var) __strong typeof(var) strongSelf = var

Expand Down
15 changes: 9 additions & 6 deletions PhotoBrowser/ZLEditVideoController.m
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ @implementation ZLEditVideoController
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
// NSLog(@"---- %s", __FUNCTION__);
}

- (NSMutableArray<UIImage *> *)arrImages
Expand Down Expand Up @@ -349,7 +350,7 @@ - (void)setupUI

- (void)creatBottomView
{
ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController;
ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration];
//下方视图
_bottomView = [[UIView alloc] init];
_bottomView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.7];
Expand All @@ -364,7 +365,7 @@ - (void)creatBottomView

_doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_doneBtn setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserDoneText) forState:UIControlStateNormal];
[_doneBtn setBackgroundColor:nav.bottomBtnsNormalTitleColor];
[_doneBtn setBackgroundColor:configuration.bottomBtnsNormalTitleColor];
[_doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_doneBtn.titleLabel.font = [UIFont systemFontOfSize:15];
_doneBtn.layer.masksToBounds = YES;
Expand All @@ -389,8 +390,8 @@ - (void)analysisAssetImages
});
}];

ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController;
_interval = nav.maxEditVideoTime/10.0;
ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration];
_interval = configuration.maxEditVideoTime/10.0;

[ZLPhotoManager analysisEverySecondsImageForAsset:self.model.asset interval:_interval size:CGSizeMake(kItemWidth*5, kItemHeight*5) complete:^(AVAsset *avAsset, NSArray<UIImage *> *images) {
[hud hide];
Expand All @@ -408,8 +409,10 @@ - (void)cancelBtn_click
[self stopTimer];

ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController;
if (nav.editAfterSelectThumbnailImage &&
nav.maxSelectCount == 1) {
ZLPhotoConfiguration *configuration = nav.configuration;

if (configuration.editAfterSelectThumbnailImage &&
configuration.maxSelectCount == 1) {
[nav.arrSelectedModels removeAllObjects];
}

Expand Down
28 changes: 17 additions & 11 deletions PhotoBrowser/ZLEditViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ @interface ZLEditViewController ()

@implementation ZLEditViewController

- (void)dealloc
{
// NSLog(@"---- %s", __FUNCTION__);
}

- (void)viewDidLoad {
[super viewDidLoad];

Expand Down Expand Up @@ -328,10 +333,10 @@ - (void)viewDidLayoutSubviews
//当裁剪比例只有 custom 或者 1:1 的时候隐藏比例视图
- (BOOL)shouldHideClipRatioView
{
ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController;
if (nav.clipRatios.count <= 1) {
NSInteger value1 = [nav.clipRatios.firstObject[ClippingRatioValue1] integerValue];
NSInteger value2 = [nav.clipRatios.firstObject[ClippingRatioValue2] integerValue];
ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration];
if (configuration.clipRatios.count <= 1) {
NSInteger value1 = [configuration.clipRatios.firstObject[ClippingRatioValue1] integerValue];
NSInteger value2 = [configuration.clipRatios.firstObject[ClippingRatioValue2] integerValue];
if ((value1==0 && value2==0) || (value1==1 && value2==1)) {
return YES;
}
Expand Down Expand Up @@ -369,7 +374,7 @@ - (void)initUI

- (void)creatBottomView
{
ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController;
ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration];
//下方视图
_bottomView = [[UIView alloc] init];
_bottomView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.7];
Expand All @@ -391,7 +396,7 @@ - (void)creatBottomView

_doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_doneBtn setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserDoneText) forState:UIControlStateNormal];
[_doneBtn setBackgroundColor:nav.bottomBtnsNormalTitleColor];
[_doneBtn setBackgroundColor:configuration.bottomBtnsNormalTitleColor];
[_doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_doneBtn.titleLabel.font = [UIFont systemFontOfSize:15];
_doneBtn.layer.masksToBounds = YES;
Expand Down Expand Up @@ -471,11 +476,10 @@ - (void)setCropMenu
CGFloat W = 70;
CGFloat x = 0;

ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController;
ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration];
//如需要其他比例,请按照格式自行设置
NSArray *ratios = nav.clipRatios;

for(NSDictionary *info in ratios){
for(NSDictionary *info in configuration.clipRatios){
CGFloat val1 = [info[@"value1"] floatValue];
CGFloat val2 = [info[@"value2"] floatValue];

Expand Down Expand Up @@ -771,8 +775,10 @@ - (void)panGridView:(UIPanGestureRecognizer*)sender
- (void)cancelBtn_click
{
ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController;
if (nav.editAfterSelectThumbnailImage &&
nav.maxSelectCount == 1) {
ZLPhotoConfiguration *configuration = nav.configuration;

if (configuration.editAfterSelectThumbnailImage &&
configuration.maxSelectCount == 1) {
[nav.arrSelectedModels removeAllObjects];
}
UIViewController *vc = [self.navigationController popViewControllerAnimated:NO];
Expand Down
197 changes: 4 additions & 193 deletions PhotoBrowser/ZLPhotoActionSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,213 +8,25 @@
//pods version 2.5.1.1 - 2017.11.15 update

#import <UIKit/UIKit.h>
#import "ZLDefine.h"

NS_ASSUME_NONNULL_BEGIN

@class ZLPhotoModel;
@class PHAsset;
@class AVPlayerItem;
@class ZLPhotoConfiguration;

@interface ZLPhotoActionSheet : UIView

@property (nonatomic, weak) UIViewController *sender;

/**
最大选择数 默认10张
*/
@property (nonatomic, assign) NSInteger maxSelectCount;

/**
预览图最大显示数 默认20张
*/
@property (nonatomic, assign) NSInteger maxPreviewCount;

/**
cell的圆角弧度 默认为0
*/
@property (nonatomic, assign) CGFloat cellCornerRadio;

/**
是否允许混合选择,即可以同时选择image(image/gif/livephoto)、video类型
*/
@property (nonatomic, assign) BOOL allowMixSelect;

/**
是否允许选择照片 默认YES
*/
@property (nonatomic, assign) BOOL allowSelectImage;

/**
是否允许选择视频 默认YES
*/
@property (nonatomic, assign) BOOL allowSelectVideo;

/**
是否允许选择Gif,只是控制是否选择,并不控制是否显示,如果为NO,则不显示gif标识 默认YES
*/
@property (nonatomic, assign) BOOL allowSelectGif;

/**
* 是否允许选择Live Photo,只是控制是否选择,并不控制是否显示,如果为NO,则不显示Live Photo标识 默认NO
* @warning ios9 以上系统支持
*/
@property (nonatomic, assign) BOOL allowSelectLivePhoto;

/**
是否允许相册内部拍照 默认YES
*/
@property (nonatomic, assign) BOOL allowTakePhotoInLibrary;

/**
是否允许Force Touch功能 默认YES
*/
@property (nonatomic, assign) BOOL allowForceTouch;

/**
是否允许编辑图片,选择一张时候才允许编辑,默认YES
*/
@property (nonatomic, assign) BOOL allowEditImage;

/**
是否允许编辑视频,选择一张时候才允许编辑,默认NO
*/
@property (nonatomic, assign) BOOL allowEditVideo;

/**
是否允许选择原图,默认YES
*/
@property (nonatomic, assign) BOOL allowSelectOriginal;

/**
编辑视频时最大裁剪时间,单位:秒,默认10s 且最低10s
@discussion 当该参数为10s时,所选视频时长必须大于等于10s才允许进行编辑
*/
@property (nonatomic, assign) NSInteger maxEditVideoTime;
/**相册框架配置*/
@property (nonatomic, strong) ZLPhotoConfiguration *configuration;

/**
允许选择视频的最大时长,单位:秒, 默认 120s
*/
@property (nonatomic, assign) NSInteger maxVideoDuration;

/**
是否允许滑动选择 默认 YES
*/
@property (nonatomic, assign) BOOL allowSlideSelect;

/**
预览界面是否允许拖拽选择 默认 NO
*/
@property (nonatomic, assign) BOOL allowDragSelect;

/**
根据需要设置自身需要的裁剪比例
@discussion e.g.:1:1,请使用ZLDefine中所提供方法 GetClipRatio(NSInteger value1, NSInteger value2),该数组可不设置,有默认比例,为(Custom, 1:1, 4:3, 3:2, 16:9)
*/
@property (nonatomic, strong) NSArray<NSDictionary *> *clipRatios;

/**
在小图界面选择 图片/视频 后直接进入编辑界面,默认NO
@discussion 编辑图片 仅在allowEditImage为YES 且 maxSelectCount为1 的情况下,置为YES有效,编辑视频则在 allowEditVideo为YES 且 maxSelectCount为1情况下,置为YES有效
*/
@property (nonatomic, assign) BOOL editAfterSelectThumbnailImage;

/**
是否在相册内部拍照按钮上面实时显示相机俘获的影像 默认 YES
*/
@property (nonatomic, assign) BOOL showCaptureImageOnTakePhotoBtn;

/**
是否升序排列,预览界面不受该参数影响,默认升序 YES
*/
@property (nonatomic, assign) BOOL sortAscending;

/**
控制单选模式下,是否显示选择按钮,默认 NO,多选模式不受控制
*/
@property (nonatomic, assign) BOOL showSelectBtn;

/**
已选择的asset对象数组
已选择的asset对象数组,用于标记已选择的图片
*/
@property (nonatomic, strong, nullable) NSMutableArray<PHAsset *> *arrSelectedAssets;

/**
导航条颜色,默认 rgb(19, 153, 231)
*/
@property (nonatomic, strong) UIColor *navBarColor;

/**
导航标题颜色,默认 rgb(255, 255, 255)
*/
@property (nonatomic, strong) UIColor *navTitleColor;

/**
底部工具条底色,默认 rgb(255, 255, 255)
*/
@property (nonatomic, strong) UIColor *bottomViewBgColor;

/**
底部工具栏按钮 可交互 状态标题颜色,底部 toolbar 按钮可交互状态title颜色均使用这个,确定按钮 可交互 的背景色为这个,默认rgb(80, 180, 234)
*/
@property (nonatomic, strong) UIColor *bottomBtnsNormalTitleColor;

/**
底部工具栏按钮 不可交互 状态标题颜色,底部 toolbar 按钮不可交互状态颜色均使用这个,确定按钮 不可交互 的背景色为这个,默认rgb(200, 200, 200)
*/
@property (nonatomic, strong) UIColor *bottomBtnsDisableBgColor;

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

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

/**
支持开发者自定义图片,但是所自定义图片资源名称必须与被替换的bundle中的图片名称一致
@example: 开发者需要替换选中与未选中的图片资源,则需要传入的数组为 @[@"btn_selected", @"btn_unselected"],则框架内会使用开发者项目中的图片资源,而其他图片则用框架bundle中的资源
*/
@property (nonatomic, strong) NSArray<NSString *> *customImageNames;

/**
回调时候是否允许框架解析图片,默认YES
如果选择了大量图片,框架一下解析大量图片会耗费一些内存,开发者此时可置为NO,拿到assets数组后自行解析,该值为NO时,回调的图片数组为nil
*/
@property (nonatomic, assign) BOOL shouldAnialysisAsset;

/**
框架语言,默认 ZLLanguageSystem (跟随系统语言)
仅切换框架内定义的语言,由于相册名字根据系统语言进行获取,所以相册列表界面为当前系统语言
*/
@property (nonatomic, assign) ZLLanguageType languageType;

/**
使用系统相机,默认NO(系统相机则只能进行拍照)
*/
@property (nonatomic, assign) BOOL useSystemCamera;

/**
是否允许录制视频(当useSystemCamera为YES时无效),默认YES
*/
@property (nonatomic, assign) BOOL allowRecordVideo;

/**
最大录制时长,默认 10s,最小为 1s
*/
@property (nonatomic, assign) NSInteger maxRecordDuration;

/**
视频清晰度,默认ZLCaptureSessionPreset1280x720
*/
@property (nonatomic, assign) ZLCaptureSessionPreset sessionPreset;

/**
选择照片回调,回调解析好的图片、对应的asset对象、是否原图
Expand Down Expand Up @@ -256,7 +68,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)showPhotoLibraryWithSender:(UIViewController *)sender;



/**
提供 预览用户已选择的照片,并可以取消已选择的照片
Expand Down
Loading

0 comments on commit c39d36d

Please sign in to comment.