Skip to content

Commit

Permalink
fix #221 优化预览网络图片及视频对URL的区分方式
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Mar 31, 2018
1 parent 292eaf9 commit f556669
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 30 deletions.
22 changes: 20 additions & 2 deletions PhotoBrowser/ZLDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
#define ClippingRatioValue2 @"value2"
#define ClippingRatioTitleFormat @"titleFormat"

#define ZLPreviewPhotoObj @"ZLPreviewPhotoObj"
#define ZLPreviewPhotoTyp @"ZLPreviewPhotoTyp"

typedef NS_ENUM(NSUInteger, ZLLanguageType) {
//跟随系统语言,默认
ZLLanguageSystem,
Expand Down Expand Up @@ -135,6 +138,22 @@ typedef NS_ENUM(NSUInteger, ZLWatermarkLocation) {
ZLWatermarkLocationBottomRight,
};

//混合预览图片时,图片类型
typedef NS_ENUM(NSUInteger, ZLPreviewPhotoType) {
ZLPreviewPhotoTypePHAsset,
ZLPreviewPhotoTypeUIImage,
ZLPreviewPhotoTypeURLImage,
ZLPreviewPhotoTypeURLVideo,
};


static inline NSDictionary * GetDictForPreviewPhoto(id obj, ZLPreviewPhotoType type) {
if (nil == obj) {
@throw [NSException exceptionWithName:@"error" reason:@"预览对象不能为空" userInfo:nil];
}
return @{ZLPreviewPhotoObj: obj, ZLPreviewPhotoTyp: @(type)};
}

static inline void SetViewWidth(UIView *view, CGFloat width) {
CGRect frame = view.frame;
frame.size.width = width;
Expand Down Expand Up @@ -236,8 +255,7 @@ static inline NSInteger GetDuration (NSString *duration) {
}


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

Expand Down
6 changes: 3 additions & 3 deletions PhotoBrowser/ZLPhotoActionSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ NS_ASSUME_NONNULL_BEGIN
/**
提供 混合预览照片及视频的方法, 相册PHAsset / 网络、本地图片 / 网络、本地视频,(需先设置 sender 参数)
@warning 由于 NSURL 框架内需要区分是图片还是视频,所以url后缀为 jpg/png/jpeg/gif 等格式按照图片处理,后缀在以上四种之外的NSURL对象均按视频处理
@warning photos 内对象请调用 ZLDefine 中 GetDictForPreviewPhoto 方法,e.g.: GetDictForPreviewPhoto(image, ZLPreviewPhotoTypeUIImage)
@param photos 接收对象 PHAsset / UIImage / NSURL(网络图片/视频url 或 本地图片/视频url)
@param photos 接收对象 ZLDefine 中 GetDictForPreviewPhoto 生成的字典
@param index 点击的照片/视频索引
@param hideToolBar 是否隐藏底部工具栏和导航右上角选择按钮
@param complete 回调 (数组内为接收的 PHAsset / UIImage / NSURL 对象)
*/
- (void)previewPhotos:(NSArray *)photos index:(NSInteger)index hideToolBar:(BOOL)hideToolBar complete:(void (^)(NSArray *photos))complete;
- (void)previewPhotos:(NSArray<NSDictionary *> *)photos index:(NSInteger)index hideToolBar:(BOOL)hideToolBar complete:(void (^)(NSArray *photos))complete;

NS_ASSUME_NONNULL_END

Expand Down
33 changes: 19 additions & 14 deletions PhotoBrowser/ZLPhotoActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,31 @@ - (void)previewSelectedPhotos:(NSArray<UIImage *> *)photos assets:(NSArray<PHAss
};
}

- (void)previewPhotos:(NSArray *)photos index:(NSInteger)index hideToolBar:(BOOL)hideToolBar complete:(nonnull void (^)(NSArray * _Nonnull))complete
- (void)previewPhotos:(NSArray<NSDictionary *> *)photos index:(NSInteger)index hideToolBar:(BOOL)hideToolBar complete:(void (^)(NSArray * _Nonnull))complete
{
NSArray *imageExtensions = @[@"jpg", @"jpeg", @"png", @"gif"];
//转换为对应类型的model对象
NSMutableArray<ZLPhotoModel *> *models = [NSMutableArray arrayWithCapacity:photos.count];
for (id obj in photos) {
for (NSDictionary *dic in photos) {
ZLPhotoModel *model = [[ZLPhotoModel alloc] init];
if ([obj isKindOfClass:UIImage.class]) {
model.image = obj;
model.type = ZLAssetMediaTypeNetImage;
} else if ([obj isKindOfClass:NSURL.class]) {
model.url = obj;
if ([imageExtensions containsObject:((NSURL *)obj).absoluteString.pathExtension]) {
ZLPreviewPhotoType type = [dic[ZLPreviewPhotoTyp] integerValue];
id obj = dic[ZLPreviewPhotoObj];
switch (type) {
case ZLPreviewPhotoTypePHAsset:
model.asset = obj;
model.type = [ZLPhotoManager transformAssetType:obj];
break;
case ZLPreviewPhotoTypeUIImage:
model.image = obj;
model.type = ZLAssetMediaTypeNetImage;
} else {
break;
case ZLPreviewPhotoTypeURLImage:
model.url = obj;
model.type = ZLAssetMediaTypeNetImage;
break;
case ZLPreviewPhotoTypeURLVideo:
model.url = obj;
model.type = ZLAssetMediaTypeNetVideo;
}
} else if ([obj isKindOfClass:PHAsset.class]) {
model.asset = obj;
model.type = [ZLPhotoManager transformAssetType:obj];
break;
}
model.selected = YES;
[models addObject:model];
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
### 更新日志
> [更多更新日志](https://github.com/longitachi/ZLPhotoBrowser/blob/master/UPDATELOG.md)
```
● 2.6.5: Fix #221, 优化预览网络图片/视频时根据url后缀判断的类型方式;
● 2.6.4: Fix #181, #184, #185;
● 2.6.3: 新增自定义多语言文本功能; 新增预览网络视频功能;
● 2.6.2: 新增是否保存已编辑图片的参数; 优化编辑图片旋转体验; 新增取消选择回调;
Expand All @@ -63,7 +64,6 @@
● 2.5.0.1: 提供逐个解析图片api,方便 shouldAnialysisAsset 为 NO 时的使用; 提供控制是否可以选择原图参数;
● 2.5.0: 新增选择后是否自动解析图片参数 shouldAnialysisAsset (针对需要选择大量图片的功能,框架一次解析大量图片时,会导致内存瞬间大幅增高,建议此时置该参数为NO,然后拿到asset后自行逐个解析); 修改图片压缩方式,确保原图尺寸不变
● 2.4.9: 新增预览界面拖拽选择的功能; 支持开发者使用自定义图片资源; 开放导航标题颜色、底部工具栏背景色、底部按钮可交互与不可交互标题颜色的设置api;
● 2.4.6: 新增网络图片长按保存至相册功能;
```

### 框架支持
Expand Down
6 changes: 6 additions & 0 deletions UPDATELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

-----

## [2.6.5](https://github.com/longitachi/ZLPhotoBrowser/releases/tag/2.6.5) (2018-03-31)

#### Fix
* 优化预览网络图片/视频时根据url后缀判断的类型方式. [#221](https://github.com/longitachi/ZLPhotoBrowser/issues/221)

---

## [2.6.4](https://github.com/longitachi/ZLPhotoBrowser/releases/tag/2.6.4) (2018-01-17)

Expand Down
2 changes: 1 addition & 1 deletion ZLPhotoBrowser.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ZLPhotoBrowser'
s.version = '2.6.4'
s.version = '2.6.5'
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'
Expand Down
17 changes: 8 additions & 9 deletions ZLPhotoBrowser/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,14 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa

- (IBAction)btnPreviewNetImageClick:(id)sender
{
NSArray *arrNetImages = @[[NSURL URLWithString:@"http://pic.962.net/up/2013-11/20131111660842038745.jpg"],
[NSURL URLWithString:@"http://pic.962.net/up/2013-11/20131111660842025734.jpg"],
[NSURL URLWithString:@"http://120.25.226.186:32812/resources/videos/minion_01.mp4"],
[NSURL URLWithString:@"http://pic.962.net/up/2013-11/20131111660842034354.jpg"],
[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1514184259027&di=a2e54cf2d5affe17acdaf1fbf19ff0af&imgtype=0&src=http%3A%2F%2Fimg5.duitang.com%2Fuploads%2Fitem%2F201212%2F25%2F20121225173302_wTjN8.jpeg"],
[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1504756336591&di=56a3c8866c95891cbb9c43f907b4f954&imgtype=0&src=http%3A%2F%2Ff5.topitme.com%2F5%2Fa0%2F42%2F111173677859242a05o.jpg"],
[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1514778897&di=286a86139915c2b6a7a06a70df787c68&imgtype=jpg&er=1&src=http%3A%2F%2Ff9.topitme.com%2F9%2Fa1%2Fc6%2F1135106720ee0c6a19o.jpg"],
[NSURL URLWithString:@"http://img.zcool.cn/community/018003591d063cb5b3086ed4627878.gif"]];
[[self getPas] previewPhotos:arrNetImages index:0 hideToolBar:YES complete:^(NSArray * _Nonnull photos) {
NSArray *arrNetImages = @[GetDictForPreviewPhoto([NSURL URLWithString:@"http://pic.962.net/up/2013-11/20131111660842025734.jpg"], ZLPreviewPhotoTypeURLImage),
GetDictForPreviewPhoto([NSURL URLWithString:@"http://120.25.226.186:32812/resources/videos/minion_01.mp4"], ZLPreviewPhotoTypeURLVideo),
GetDictForPreviewPhoto([NSURL URLWithString:@"http://pic.962.net/up/2013-11/20131111660842034354.jpg"], ZLPreviewPhotoTypeURLImage),
GetDictForPreviewPhoto([NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1514184259027&di=a2e54cf2d5affe17acdaf1fbf19ff0af&imgtype=0&src=http%3A%2F%2Fimg5.duitang.com%2Fuploads%2Fitem%2F201212%2F25%2F20121225173302_wTjN8.jpeg"], ZLPreviewPhotoTypeURLImage),
GetDictForPreviewPhoto([NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1504756336591&di=56a3c8866c95891cbb9c43f907b4f954&imgtype=0&src=http%3A%2F%2Ff5.topitme.com%2F5%2Fa0%2F42%2F111173677859242a05o.jpg"], ZLPreviewPhotoTypeURLImage),
GetDictForPreviewPhoto([NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1514778897&di=286a86139915c2b6a7a06a70df787c68&imgtype=jpg&er=1&src=http%3A%2F%2Ff9.topitme.com%2F9%2Fa1%2Fc6%2F1135106720ee0c6a19o.jpg"], ZLPreviewPhotoTypeURLImage),
GetDictForPreviewPhoto([NSURL URLWithString:@"http://img.zcool.cn/community/018003591d063cb5b3086ed4627878.gif"], ZLPreviewPhotoTypeURLImage)];
[[self getPas] previewPhotos:arrNetImages index:0 hideToolBar:NO complete:^(NSArray * _Nonnull photos) {
NSLog(@"%@", photos);
}];
}
Expand Down

0 comments on commit f556669

Please sign in to comment.