From 5cab400635cdcf4c51e2ca6fd71ef8630a8a2a30 Mon Sep 17 00:00:00 2001 From: "yuzheng.tz" Date: Thu, 30 Aug 2018 19:45:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AF=B9GIF=E5=9B=BE?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E7=9A=84=E6=94=AF=E6=8C=81=EF=BC=8C=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Podfile | 2 +- Podfile.lock | 8 +- Pods/Manifest.lock | 8 +- Pods/Pods.xcodeproj/project.pbxproj | 18 ++-- Pods/TZImagePickerController/README.md | 3 +- .../TZImagePickerController/TZImageManager.h | 10 ++- .../TZImagePickerController/TZImageManager.m | 32 +++++-- .../TZImagePickerController.h | 2 +- .../TZImagePickerController.m | 2 +- .../TZPhotoPickerController.m | 90 +++++++++---------- .../TZPhotoPreviewController.m | 4 + TZImagePreviewController.podspec | 6 +- .../project.pbxproj | 13 ++- TZImagePreviewController/Info.plist | 23 +++-- .../TZImagePreviewController.h | 2 +- .../TZImagePreviewController.m | 16 ++-- TZImagePreviewController/TZTestCell.m | 7 +- TZImagePreviewController/ViewController.m | 29 +++++- 18 files changed, 158 insertions(+), 117 deletions(-) diff --git a/Podfile b/Podfile index 84e37f5..af61460 100644 --- a/Podfile +++ b/Podfile @@ -3,6 +3,6 @@ platform:ios,"8.0" inhibit_all_warnings! target 'TZImagePreviewController' do - pod 'TZImagePickerController', '3.0.1' + pod 'TZImagePickerController', '3.0.2' pod 'SDWebImage' end diff --git a/Podfile.lock b/Podfile.lock index e61731d..72d2992 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -2,16 +2,16 @@ PODS: - SDWebImage (4.4.2): - SDWebImage/Core (= 4.4.2) - SDWebImage/Core (4.4.2) - - TZImagePickerController (3.0.1) + - TZImagePickerController (3.0.2) DEPENDENCIES: - SDWebImage - - TZImagePickerController (= 3.0.1) + - TZImagePickerController (= 3.0.2) SPEC CHECKSUMS: SDWebImage: 624d6e296c69b244bcede364c72ae0430ac14681 - TZImagePickerController: bcec66c93c3e519dafab72e989c641b64bbd2df5 + TZImagePickerController: c6736038f5016a8be14132fd07e4e92ce6496385 -PODFILE CHECKSUM: 96ced2b50b5f473b90faad2fd01a0c6c08a4d787 +PODFILE CHECKSUM: b78ae35578264f7c650083051a27bb6b28c6c662 COCOAPODS: 1.3.1 diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock index e61731d..72d2992 100644 --- a/Pods/Manifest.lock +++ b/Pods/Manifest.lock @@ -2,16 +2,16 @@ PODS: - SDWebImage (4.4.2): - SDWebImage/Core (= 4.4.2) - SDWebImage/Core (4.4.2) - - TZImagePickerController (3.0.1) + - TZImagePickerController (3.0.2) DEPENDENCIES: - SDWebImage - - TZImagePickerController (= 3.0.1) + - TZImagePickerController (= 3.0.2) SPEC CHECKSUMS: SDWebImage: 624d6e296c69b244bcede364c72ae0430ac14681 - TZImagePickerController: bcec66c93c3e519dafab72e989c641b64bbd2df5 + TZImagePickerController: c6736038f5016a8be14132fd07e4e92ce6496385 -PODFILE CHECKSUM: 96ced2b50b5f473b90faad2fd01a0c6c08a4d787 +PODFILE CHECKSUM: b78ae35578264f7c650083051a27bb6b28c6c662 COCOAPODS: 1.3.1 diff --git a/Pods/Pods.xcodeproj/project.pbxproj b/Pods/Pods.xcodeproj/project.pbxproj index afadf38..9334ff5 100644 --- a/Pods/Pods.xcodeproj/project.pbxproj +++ b/Pods/Pods.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 50; objects = { /* Begin PBXBuildFile section */ @@ -127,7 +127,7 @@ 1248C001673FA1FCD4DB071754101528 /* SDWebImageDownloaderOperation.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SDWebImageDownloaderOperation.m; path = SDWebImage/SDWebImageDownloaderOperation.m; sourceTree = ""; }; 138F27FE7AE86815007C42DEAB13E6D6 /* UIView+WebCache.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "UIView+WebCache.h"; path = "SDWebImage/UIView+WebCache.h"; sourceTree = ""; }; 15334C6C4DF61F6DC1BAD4CBC40C1526 /* Pods-TZImagePreviewController.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-TZImagePreviewController.release.xcconfig"; sourceTree = ""; }; - 178893F06FC03E5101A699A92A5DB854 /* libTZImagePickerController.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libTZImagePickerController.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 178893F06FC03E5101A699A92A5DB854 /* libTZImagePickerController.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libTZImagePickerController.a; path = libTZImagePickerController.a; sourceTree = BUILT_PRODUCTS_DIR; }; 18A1C7DE167C08B17A517856B8862DF9 /* TZAssetModel.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = TZAssetModel.h; path = TZImagePickerController/TZImagePickerController/TZAssetModel.h; sourceTree = ""; }; 1C78E7ABD09F5C48446409A40721E2DF /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk/System/Library/Frameworks/ImageIO.framework; sourceTree = DEVELOPER_DIR; }; 1CC7D6746DEE0BDB09E983CE6B10EAFC /* TZImageManager.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = TZImageManager.m; path = TZImagePickerController/TZImagePickerController/TZImageManager.m; sourceTree = ""; }; @@ -160,7 +160,7 @@ 5301D03826CB71B7F0E94E7781773CA1 /* UIImage+GIF.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "UIImage+GIF.m"; path = "SDWebImage/UIImage+GIF.m"; sourceTree = ""; }; 53AB0D47BC1A6EAA3470269669FE0227 /* SDWebImageGIFCoder.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = SDWebImageGIFCoder.h; path = SDWebImage/SDWebImageGIFCoder.h; sourceTree = ""; }; 551ED56FC457AB592A3AFB148E6A4AD4 /* SDWebImageGIFCoder.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SDWebImageGIFCoder.m; path = SDWebImage/SDWebImageGIFCoder.m; sourceTree = ""; }; - 555BDBB7E3E0CF3166CF1F1E79A9DAC8 /* libPods-TZImagePreviewController.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-TZImagePreviewController.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 555BDBB7E3E0CF3166CF1F1E79A9DAC8 /* libPods-TZImagePreviewController.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-TZImagePreviewController.a"; path = "libPods-TZImagePreviewController.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 578F7276656662E591EC638FB3B0D738 /* Pods-TZImagePreviewController-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-TZImagePreviewController-acknowledgements.markdown"; sourceTree = ""; }; 5E760A1FDF263BF7E6056E171F26291C /* TZAssetModel.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = TZAssetModel.m; path = TZImagePickerController/TZImagePickerController/TZAssetModel.m; sourceTree = ""; }; 65C48C85C82DF855C11C2B26C2AB139E /* SDImageCacheConfig.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SDImageCacheConfig.m; path = SDWebImage/SDImageCacheConfig.m; sourceTree = ""; }; @@ -175,7 +175,7 @@ 833D5D456949D7DDAA3A4E71D439C7BF /* TZImagePickerController.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = TZImagePickerController.h; path = TZImagePickerController/TZImagePickerController/TZImagePickerController.h; sourceTree = ""; }; 87AED9C0AF04FB8A40FAA12EC5E016F8 /* SDWebImageDownloaderOperation.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = SDWebImageDownloaderOperation.h; path = SDWebImage/SDWebImageDownloaderOperation.h; sourceTree = ""; }; 8F8048FD2A468115C0325B03A9ABE170 /* TZImageCropManager.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = TZImageCropManager.m; path = TZImagePickerController/TZImagePickerController/TZImageCropManager.m; sourceTree = ""; }; - 93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + 93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; A3BBDD6935F59684EA447DF5E7237D90 /* SDWebImagePrefetcher.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SDWebImagePrefetcher.m; path = SDWebImage/SDWebImagePrefetcher.m; sourceTree = ""; }; A49DC4B4A77B3F3A156D4EE1A003DF53 /* NSImage+WebCache.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "NSImage+WebCache.m"; path = "SDWebImage/NSImage+WebCache.m"; sourceTree = ""; }; A5DC12D18E05E2747ECDA65325A49D5A /* NSBundle+TZImagePicker.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "NSBundle+TZImagePicker.h"; path = "TZImagePickerController/TZImagePickerController/NSBundle+TZImagePicker.h"; sourceTree = ""; }; @@ -185,7 +185,7 @@ B1D6ECB517C5C02CE3FEBE11D2CBE5B2 /* Pods-TZImagePreviewController.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-TZImagePreviewController.debug.xcconfig"; sourceTree = ""; }; B2B51AB71875E71132EF0C3B05E7D71A /* NSData+ImageContentType.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "NSData+ImageContentType.m"; path = "SDWebImage/NSData+ImageContentType.m"; sourceTree = ""; }; B327BFCA5CEE67EF5F26191EE6E2456B /* NSButton+WebCache.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "NSButton+WebCache.m"; path = "SDWebImage/NSButton+WebCache.m"; sourceTree = ""; }; - B42955191C3DBC9907D29A534C04900B /* libSDWebImage.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libSDWebImage.a; sourceTree = BUILT_PRODUCTS_DIR; }; + B42955191C3DBC9907D29A534C04900B /* libSDWebImage.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libSDWebImage.a; path = libSDWebImage.a; sourceTree = BUILT_PRODUCTS_DIR; }; B9A63161A7A76D22F601ACCB7C38FD16 /* TZPhotoPreviewCell.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = TZPhotoPreviewCell.h; path = TZImagePickerController/TZImagePickerController/TZPhotoPreviewCell.h; sourceTree = ""; }; B9D50F8C9CEDF2BCEBD85A51891F2483 /* Pods-TZImagePreviewController-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-TZImagePreviewController-acknowledgements.plist"; sourceTree = ""; }; BCD8FAE1D53F67FBCF52F485F19AE2EC /* SDWebImage-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "SDWebImage-dummy.m"; sourceTree = ""; }; @@ -382,6 +382,7 @@ 8994AE8E6F937196C1244A7891B935E9 /* Resources */, 505E5C6AAB907CB64CE43618F1467BAF /* Support Files */, ); + name = TZImagePickerController; path = TZImagePickerController; sourceTree = ""; }; @@ -443,6 +444,7 @@ 299AF1050790339067998F0E1EA921AD /* Core */, E47007D0C281637074B6A19D2794B2DA /* Support Files */, ); + name = SDWebImage; path = SDWebImage; sourceTree = ""; }; @@ -577,7 +579,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0930; - LastUpgradeCheck = 1000; + LastUpgradeCheck = 0930; }; buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */; compatibilityVersion = "Xcode 3.2"; @@ -690,7 +692,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; GCC_PREFIX_HEADER = "Target Support Files/SDWebImage/SDWebImage-prefix.pch"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; OTHER_LDFLAGS = ""; OTHER_LIBTOOLFLAGS = ""; PRIVATE_HEADERS_FOLDER_PATH = ""; @@ -896,7 +898,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; GCC_PREFIX_HEADER = "Target Support Files/SDWebImage/SDWebImage-prefix.pch"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; OTHER_LDFLAGS = ""; OTHER_LIBTOOLFLAGS = ""; PRIVATE_HEADERS_FOLDER_PATH = ""; diff --git a/Pods/TZImagePickerController/README.md b/Pods/TZImagePickerController/README.md index db96b92..c48b47c 100644 --- a/Pods/TZImagePickerController/README.md +++ b/Pods/TZImagePickerController/README.md @@ -120,7 +120,8 @@ A:视频导出分两步,第一步是通过PHAsset获取AVURLAsset,如是iC ## 六. Release Notes 最近更新 -3.0.1 新增对[TZImagePreviewController](https://github.com/banchichen/TZImagePreviewController)库的支持,允许预览UIImage、NSURL、PHAsset对象。 +3.0.2 优化保存照片、视频的方法 +3.0.1 新增对[TZImagePreviewController](https://github.com/banchichen/TZImagePreviewController)库的支持,允许预览UIImage、NSURL、PHAsset对象 **3.0.0 去除iOS6和7的适配代码,更轻量,最低支持iOS8** 2.2.6 新增needFixComposition属性,默认为NO,不再主动修正视频转向,防止部分安卓拍的视频导出失败(**最后一个支持iOS6和7的版本**) 2.1.5 修复开启showSelectedIndex后照片列表页iCloud图片进度条紊乱的bug diff --git a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImageManager.h b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImageManager.h index 4dadc22..5858207 100755 --- a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImageManager.h +++ b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImageManager.h @@ -75,12 +75,12 @@ - (void)getOriginalPhotoDataWithAsset:(PHAsset *)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion; /// Save photo 保存照片 -- (void)savePhotoWithImage:(UIImage *)image completion:(void (^)(NSError *error))completion; -- (void)savePhotoWithImage:(UIImage *)image location:(CLLocation *)location completion:(void (^)(NSError *error))completion; +- (void)savePhotoWithImage:(UIImage *)image completion:(void (^)(PHAsset *asset, NSError *error))completion; +- (void)savePhotoWithImage:(UIImage *)image location:(CLLocation *)location completion:(void (^)(PHAsset *asset, NSError *error))completion; /// Save video 保存视频 -- (void)saveVideoWithUrl:(NSURL *)url completion:(void (^)(NSError *error))completion; -- (void)saveVideoWithUrl:(NSURL *)url location:(CLLocation *)location completion:(void (^)(NSError *error))completion; +- (void)saveVideoWithUrl:(NSURL *)url completion:(void (^)(PHAsset *asset, NSError *error))completion; +- (void)saveVideoWithUrl:(NSURL *)url location:(CLLocation *)location completion:(void (^)(PHAsset *asset, NSError *error))completion; /// Get video 获得视频 - (void)getVideoWithAsset:(PHAsset *)asset completion:(void (^)(AVPlayerItem * playerItem, NSDictionary * info))completion; @@ -114,6 +114,8 @@ /// for TZImagePreviewController - (NSString *)getNewTimeFromDurationSecond:(NSInteger)duration; +- (TZAssetModel *)createModelWithAsset:(PHAsset *)asset; + @end //@interface TZSortDescriptor : NSSortDescriptor diff --git a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImageManager.m b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImageManager.m index 8172d01..52d5e10 100755 --- a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImageManager.m +++ b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImageManager.m @@ -457,17 +457,19 @@ - (void)getOriginalPhotoDataWithAsset:(PHAsset *)asset progressHandler:(void (^) #pragma mark - Save photo -- (void)savePhotoWithImage:(UIImage *)image completion:(void (^)(NSError *error))completion { +- (void)savePhotoWithImage:(UIImage *)image completion:(void (^)(PHAsset *asset, NSError *error))completion { [self savePhotoWithImage:image location:nil completion:completion]; } -- (void)savePhotoWithImage:(UIImage *)image location:(CLLocation *)location completion:(void (^)(NSError *error))completion { +- (void)savePhotoWithImage:(UIImage *)image location:(CLLocation *)location completion:(void (^)(PHAsset *asset, NSError *error))completion { + __block NSString *localIdentifier = nil; [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ if (@available(iOS 9, *)) { NSData *data = UIImageJPEGRepresentation(image, 0.9); PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init]; options.shouldMoveFile = YES; PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset]; + localIdentifier = request.placeholderForCreatedAsset.localIdentifier; [request addResourceWithType:PHAssetResourceTypePhoto data:data options:options]; if (location) { request.location = location; @@ -475,6 +477,7 @@ - (void)savePhotoWithImage:(UIImage *)image location:(CLLocation *)location comp request.creationDate = [NSDate date]; } else { PHAssetChangeRequest *request = [PHAssetChangeRequest creationRequestForAssetFromImage:image]; + localIdentifier = request.placeholderForCreatedAsset.localIdentifier; if (location) { request.location = location; } @@ -483,11 +486,12 @@ - (void)savePhotoWithImage:(UIImage *)image location:(CLLocation *)location comp } completionHandler:^(BOOL success, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ if (success && completion) { - completion(nil); + PHAsset *asset = [[PHAsset fetchAssetsWithLocalIdentifiers:@[localIdentifier] options:nil] firstObject]; + completion(asset, nil); } else if (error) { NSLog(@"保存照片出错:%@",error.localizedDescription); if (completion) { - completion(error); + completion(nil, error); } } }); @@ -496,16 +500,18 @@ - (void)savePhotoWithImage:(UIImage *)image location:(CLLocation *)location comp #pragma mark - Save video -- (void)saveVideoWithUrl:(NSURL *)url completion:(void (^)(NSError *error))completion { +- (void)saveVideoWithUrl:(NSURL *)url completion:(void (^)(PHAsset *asset, NSError *error))completion { [self saveVideoWithUrl:url location:nil completion:completion]; } -- (void)saveVideoWithUrl:(NSURL *)url location:(CLLocation *)location completion:(void (^)(NSError *error))completion { +- (void)saveVideoWithUrl:(NSURL *)url location:(CLLocation *)location completion:(void (^)(PHAsset *asset, NSError *error))completion { + __block NSString *localIdentifier = nil; [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ if (@available(iOS 9, *)) { PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init]; options.shouldMoveFile = YES; PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset]; + localIdentifier = request.placeholderForCreatedAsset.localIdentifier; [request addResourceWithType:PHAssetResourceTypeVideo fileURL:url options:options]; if (location) { request.location = location; @@ -513,6 +519,7 @@ - (void)saveVideoWithUrl:(NSURL *)url location:(CLLocation *)location completion request.creationDate = [NSDate date]; } else { PHAssetChangeRequest *request = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:url]; + localIdentifier = request.placeholderForCreatedAsset.localIdentifier; if (location) { request.location = location; } @@ -521,11 +528,12 @@ - (void)saveVideoWithUrl:(NSURL *)url location:(CLLocation *)location completion } completionHandler:^(BOOL success, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ if (success && completion) { - completion(nil); + PHAsset *asset = [[PHAsset fetchAssetsWithLocalIdentifiers:@[localIdentifier] options:nil] firstObject]; + completion(asset, nil); } else if (error) { NSLog(@"保存视频出错:%@",error.localizedDescription); if (completion) { - completion(error); + completion(nil, error); } } }); @@ -734,6 +742,14 @@ - (BOOL)isVideo:(PHAsset *)asset { return asset.mediaType == PHAssetMediaTypeVideo; } +- (TZAssetModel *)createModelWithAsset:(PHAsset *)asset { + TZAssetModelMediaType type = [[TZImageManager manager] getAssetType:asset]; + NSString *timeLength = type == TZAssetModelMediaTypeVideo ? [NSString stringWithFormat:@"%0.0f",asset.duration] : @""; + timeLength = [[TZImageManager manager] getNewTimeFromDurationSecond:timeLength.integerValue]; + TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:type timeLength:timeLength]; + return model; +} + /// 获取优化后的视频转向信息 - (AVMutableVideoComposition *)fixedCompositionWithAsset:(AVAsset *)videoAsset { AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition]; diff --git a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImagePickerController.h b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImagePickerController.h index c62f81a..a708f42 100644 --- a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImagePickerController.h +++ b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImagePickerController.h @@ -4,7 +4,7 @@ // // Created by 谭真 on 15/12/24. // Copyright © 2015年 谭真. All rights reserved. -// version 3.0.1 - 2018.08.27 +// version 3.0.2 - 2018.08.28 // 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController /* diff --git a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImagePickerController.m b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImagePickerController.m index e090703..b2c3ff8 100644 --- a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImagePickerController.m +++ b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImagePickerController.m @@ -4,7 +4,7 @@ // // Created by 谭真 on 15/12/24. // Copyright © 2015年 谭真. All rights reserved. -// version 3.0.1 - 2018.08.27 +// version 3.0.2 - 2018.08.28 // 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController #import "TZImagePickerController.h" diff --git a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m index 904dabe..1dbb25a 100755 --- a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m +++ b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m @@ -787,9 +787,9 @@ - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingM [imagePickerVc showProgressHUD]; UIImage *photo = [info objectForKey:UIImagePickerControllerOriginalImage]; if (photo) { - [[TZImageManager manager] savePhotoWithImage:photo location:self.location completion:^(NSError *error){ + [[TZImageManager manager] savePhotoWithImage:photo location:self.location completion:^(PHAsset *asset, NSError *error){ if (!error) { - [self reloadPhotoArrayWithMediaType:type]; + [self addPHAsset:asset]; } }]; self.location = nil; @@ -799,9 +799,9 @@ - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingM [imagePickerVc showProgressHUD]; NSURL *videoUrl = [info objectForKey:UIImagePickerControllerMediaURL]; if (videoUrl) { - [[TZImageManager manager] saveVideoWithUrl:videoUrl location:self.location completion:^(NSError *error) { + [[TZImageManager manager] saveVideoWithUrl:videoUrl location:self.location completion:^(PHAsset *asset, NSError *error) { if (!error) { - [self reloadPhotoArrayWithMediaType:type]; + [self addPHAsset:asset]; } }]; self.location = nil; @@ -809,55 +809,47 @@ - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingM } } -- (void)reloadPhotoArrayWithMediaType:(NSString *)mediaType { +- (void)addPHAsset:(PHAsset *)asset { + TZAssetModel *assetModel = [[TZImageManager manager] createModelWithAsset:asset]; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; - [[TZImageManager manager] getCameraRollAlbum:tzImagePickerVc.allowPickingVideo allowPickingImage:tzImagePickerVc.allowPickingImage needFetchAssets:NO completion:^(TZAlbumModel *model) { - self->_model = model; - [[TZImageManager manager] getAssetsFromFetchResult:self->_model.result completion:^(NSArray *models) { - [tzImagePickerVc hideProgressHUD]; - - TZAssetModel *assetModel; + [tzImagePickerVc hideProgressHUD]; + if (tzImagePickerVc.sortAscendingByModificationDate) { + [_models addObject:assetModel]; + } else { + [_models insertObject:assetModel atIndex:0]; + } + + if (tzImagePickerVc.maxImagesCount <= 1) { + if (tzImagePickerVc.allowCrop && asset.mediaType == PHAssetMediaTypeImage) { + TZPhotoPreviewController *photoPreviewVc = [[TZPhotoPreviewController alloc] init]; if (tzImagePickerVc.sortAscendingByModificationDate) { - assetModel = [models lastObject]; - [self->_models addObject:assetModel]; + photoPreviewVc.currentIndex = _models.count - 1; } else { - assetModel = [models firstObject]; - [self->_models insertObject:assetModel atIndex:0]; + photoPreviewVc.currentIndex = 0; } - - if (tzImagePickerVc.maxImagesCount <= 1) { - if (tzImagePickerVc.allowCrop) { - TZPhotoPreviewController *photoPreviewVc = [[TZPhotoPreviewController alloc] init]; - if (tzImagePickerVc.sortAscendingByModificationDate) { - photoPreviewVc.currentIndex = self->_models.count - 1; - } else { - photoPreviewVc.currentIndex = 0; - } - photoPreviewVc.models = self->_models; - [self pushPhotoPrevireViewController:photoPreviewVc]; - } else { - [tzImagePickerVc addSelectedModel:assetModel]; - [self doneButtonClick]; - } - return; - } - - if (tzImagePickerVc.selectedModels.count < tzImagePickerVc.maxImagesCount) { - if ([mediaType isEqualToString:@"public.movie"] && !tzImagePickerVc.allowPickingMultipleVideo) { - // 不能多选视频的情况下,不选中拍摄的视频 - } else { - assetModel.isSelected = YES; - [tzImagePickerVc addSelectedModel:assetModel]; - [self refreshBottomToolBarStatus]; - } - } - self->_collectionView.hidden = YES; - [self->_collectionView reloadData]; - - self->_shouldScrollToBottom = YES; - [self scrollCollectionViewToBottom]; - }]; - }]; + photoPreviewVc.models = _models; + [self pushPhotoPrevireViewController:photoPreviewVc]; + } else { + [tzImagePickerVc addSelectedModel:assetModel]; + [self doneButtonClick]; + } + return; + } + + if (tzImagePickerVc.selectedModels.count < tzImagePickerVc.maxImagesCount) { + if (assetModel.type == TZAssetModelMediaTypeVideo && !tzImagePickerVc.allowPickingMultipleVideo) { + // 不能多选视频的情况下,不选中拍摄的视频 + } else { + assetModel.isSelected = YES; + [tzImagePickerVc addSelectedModel:assetModel]; + [self refreshBottomToolBarStatus]; + } + } + _collectionView.hidden = YES; + [_collectionView reloadData]; + + _shouldScrollToBottom = YES; + [self scrollCollectionViewToBottom]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { diff --git a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m index 32c003b..9908db6 100644 --- a/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m +++ b/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m @@ -382,12 +382,16 @@ - (void)doneButtonClick { [_tzImagePickerVc addSelectedModel:model]; } if (_tzImagePickerVc.allowCrop) { // 裁剪状态 + _doneButton.enabled = NO; + [_tzImagePickerVc showProgressHUD]; NSIndexPath *indexPath = [NSIndexPath indexPathForItem:_currentIndex inSection:0]; TZPhotoPreviewCell *cell = (TZPhotoPreviewCell *)[_collectionView cellForItemAtIndexPath:indexPath]; UIImage *cropedImage = [TZImageCropManager cropImageView:cell.previewView.imageView toRect:_tzImagePickerVc.cropRect zoomScale:cell.previewView.scrollView.zoomScale containerView:self.view]; if (_tzImagePickerVc.needCircleCrop) { cropedImage = [TZImageCropManager circularClipImage:cropedImage]; } + _doneButton.enabled = YES; + [_tzImagePickerVc hideProgressHUD]; if (self.doneButtonClickBlockCropMode) { TZAssetModel *model = _models[_currentIndex]; self.doneButtonClickBlockCropMode(cropedImage,model.asset); diff --git a/TZImagePreviewController.podspec b/TZImagePreviewController.podspec index 07c3d28..7e98a0d 100644 --- a/TZImagePreviewController.podspec +++ b/TZImagePreviewController.podspec @@ -1,15 +1,15 @@ Pod::Spec.new do |s| s.name = "TZImagePreviewController" - s.version = "0.1.1" + s.version = "0.2.0" s.summary = "Enhance the TZImagePickerController library, supports to preview photos with UIImage or NSURL." s.homepage = "https://github.com/banchichen/TZImagePreviewController" s.license = "MIT" s.author = { "banchichen" => "tanzhenios@foxmail.com" } s.platform = :ios s.ios.deployment_target = "8.0" - s.source = { :git => "https://github.com/banchichen/TZImagePreviewController.git", :tag => "0.1.1" } + s.source = { :git => "https://github.com/banchichen/TZImagePreviewController.git", :tag => "0.2.0" } s.requires_arc = true s.source_files = "TZImagePreviewController/TZImagePreviewController/*.{h,m}" s.frameworks = "Photos" - s.dependency 'TZImagePickerController', '>=3.0.1' + s.dependency 'TZImagePickerController', '>=3.0.2' end diff --git a/TZImagePreviewController.xcodeproj/project.pbxproj b/TZImagePreviewController.xcodeproj/project.pbxproj index bb261ea..029695f 100644 --- a/TZImagePreviewController.xcodeproj/project.pbxproj +++ b/TZImagePreviewController.xcodeproj/project.pbxproj @@ -196,9 +196,12 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-TZImagePreviewController/Pods-TZImagePreviewController-resources.sh", + "${PODS_ROOT}/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImagePickerController.bundle", ); name = "[CP] Copy Pods Resources"; outputPaths = ( + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -394,10 +397,7 @@ DEVELOPMENT_TEAM = T86X98NCU2; INFOPLIST_FILE = TZImagePreviewController/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = tanzhen.TZImagePreviewController.www; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; @@ -413,10 +413,7 @@ DEVELOPMENT_TEAM = T86X98NCU2; INFOPLIST_FILE = TZImagePreviewController/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = tanzhen.TZImagePreviewController.www; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/TZImagePreviewController/Info.plist b/TZImagePreviewController/Info.plist index a2de23a..8c6651b 100644 --- a/TZImagePreviewController/Info.plist +++ b/TZImagePreviewController/Info.plist @@ -15,19 +15,24 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 - NSPhotoLibraryUsageDescription - 访问相册以选择照片 - NSLocationWhenInUseUsageDescription - 允许定位以把位置保存到照片中 - NSCameraUsageDescription - 访问相机以拍照 - NSMicrophoneUsageDescription - 访问麦克风以录像 + 0.2.0 CFBundleVersion 1 LSRequiresIPhoneOS + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + NSCameraUsageDescription + 访问相机以拍照 + NSLocationWhenInUseUsageDescription + 允许定位以把位置保存到照片中 + NSMicrophoneUsageDescription + 访问麦克风以录像 + NSPhotoLibraryUsageDescription + 访问相册以选择照片 UILaunchStoryboardName LaunchScreen UIMainStoryboardFile diff --git a/TZImagePreviewController/TZImagePreviewController/TZImagePreviewController.h b/TZImagePreviewController/TZImagePreviewController/TZImagePreviewController.h index 72aa2e5..c677fe8 100644 --- a/TZImagePreviewController/TZImagePreviewController/TZImagePreviewController.h +++ b/TZImagePreviewController/TZImagePreviewController/TZImagePreviewController.h @@ -25,7 +25,7 @@ @property (nonatomic, assign) BOOL isSelectOriginalPhoto; /// 传入的photos有NSURL对象时会触发,请使用你依赖的图片库给imageView设置图片 -@property (nonatomic, copy) void (^setImageWithURLBlock)(NSURL *URL, UIImageView *imageView); +@property (nonatomic, copy) void (^setImageWithURLBlock)(NSURL *URL, UIImageView *imageView, void (^completion)(void)); /// 用户点击了返回按钮 @property (nonatomic, copy) void (^backButtonClickBlock)(BOOL isSelectOriginalPhoto); /// 用户点击了完成按钮 diff --git a/TZImagePreviewController/TZImagePreviewController/TZImagePreviewController.m b/TZImagePreviewController/TZImagePreviewController/TZImagePreviewController.m index e3af417..0c9fac4 100644 --- a/TZImagePreviewController/TZImagePreviewController/TZImagePreviewController.m +++ b/TZImagePreviewController/TZImagePreviewController/TZImagePreviewController.m @@ -340,7 +340,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell if ([photo isKindOfClass:[PHAsset class]]) { PHAsset *asset = (PHAsset *)photo; - TZAssetModel *model = [self createModelWithAsset:asset]; + TZAssetModel *model = [[TZImageManager manager] createModelWithAsset:asset]; if (_tzImagePickerVc.allowPickingMultipleVideo && model.type == TZAssetModelMediaTypeVideo) { cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZVideoPreviewCell" forIndexPath:indexPath]; @@ -376,7 +376,9 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell photoPreviewCell.previewView.imageView.image = (UIImage *)photo; } else if ([photo isKindOfClass:[NSURL class]]) { if (self.setImageWithURLBlock) { - self.setImageWithURLBlock((NSURL *)photo, photoPreviewCell.previewView.imageView); + self.setImageWithURLBlock((NSURL *)photo, photoPreviewCell.previewView.imageView, ^{ + [photoPreviewCell recoverSubviews]; + }); } else { photoPreviewCell.previewView.imageView.image = nil; NSLog(@"【TZImagePreviewController】传入的photos有NSURL对象,请参照Demo实现setImageWithURLBlock!"); @@ -471,19 +473,11 @@ - (void)showPhotoBytes { id photo = _photos[_currentIndex]; if ([photo isKindOfClass:[PHAsset class]]) { PHAsset *asset = (PHAsset *)photo; - TZAssetModel *model = [self createModelWithAsset:asset]; + TZAssetModel *model = [[TZImageManager manager] createModelWithAsset:asset]; [[TZImageManager manager] getPhotosBytesWithArray:@[model] completion:^(NSString *totalBytes) { self->_originalPhotoLabel.text = [NSString stringWithFormat:@"(%@)",totalBytes]; }]; } } -- (TZAssetModel *)createModelWithAsset:(PHAsset *)asset { - TZAssetModelMediaType type = [[TZImageManager manager] getAssetType:asset]; - NSString *timeLength = type == TZAssetModelMediaTypeVideo ? [NSString stringWithFormat:@"%0.0f",asset.duration] : @""; - timeLength = [[TZImageManager manager] getNewTimeFromDurationSecond:timeLength.integerValue]; - TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:type timeLength:timeLength]; - return model; -} - @end diff --git a/TZImagePreviewController/TZTestCell.m b/TZImagePreviewController/TZTestCell.m index a7d8d6d..cce9c89 100644 --- a/TZImagePreviewController/TZTestCell.m +++ b/TZImagePreviewController/TZTestCell.m @@ -62,7 +62,12 @@ - (void)setAsset:(PHAsset *)asset { _gifLable.hidden = ![[asset valueForKey:@"filename"] containsString:@"GIF"]; } else { _videoImageView.hidden = YES; - _gifLable.hidden = YES; + if ([asset isKindOfClass:[NSURL class]]) { + NSURL *URL = (NSURL *)asset; + _gifLable.hidden = ![URL.absoluteString.lowercaseString hasSuffix:@"gif"]; + } else { + _gifLable.hidden = YES; + } } } diff --git a/TZImagePreviewController/ViewController.m b/TZImagePreviewController/ViewController.m index 7f55773..afade0b 100644 --- a/TZImagePreviewController/ViewController.m +++ b/TZImagePreviewController/ViewController.m @@ -15,6 +15,7 @@ #import "TZAssetCell.h" #import "TZImagePreviewController.h" #import +#import @interface ViewController () { CGFloat _itemWH; @@ -32,8 +33,10 @@ - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; _selectedPhotos = [NSMutableArray array]; + [self.selectedPhotos addObject:[NSURL URLWithString:@"http://wx1.sinaimg.cn/bmiddle/784fda03gy1fuoxgoy1f4g209u04snpe.gif"]]; [self.selectedPhotos addObject:[UIImage imageNamed:@"photo_delete"]]; [self.selectedPhotos addObject:[NSURL URLWithString:@"https://github.com/banchichen/TZImagePickerController/raw/master/TZImagePickerController/ScreenShots/photoPickerVc.PNG"]]; + [self.selectedPhotos addObject:[NSURL URLWithString:@"http://ww1.sinaimg.cn/bmiddle/b2664ecdly1fuphxvilsdg204306v1kx.gif"]]; [self configCollectionView]; } @@ -84,7 +87,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell if ([photo isKindOfClass:[UIImage class]]) { cell.imageView.image = photo; } else if ([photo isKindOfClass:[NSURL class]]) { - [cell.imageView sd_setImageWithURL:(NSURL *)photo]; + [self configImageView:cell.imageView URL:(NSURL *)photo completion:nil]; } else if ([photo isKindOfClass:[PHAsset class]]) { [[TZImageManager manager] getPhotoWithAsset:photo photoWidth:100 completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) { cell.imageView.image = photo; @@ -113,8 +116,8 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa self.isSelectOriginalPhoto = isSelectOriginalPhoto; NSLog(@"预览页 返回 isSelectOriginalPhoto:%d", isSelectOriginalPhoto); }]; - [previewVc setSetImageWithURLBlock:^(NSURL *URL, UIImageView *imageView) { - [imageView sd_setImageWithURL:URL]; + [previewVc setSetImageWithURLBlock:^(NSURL *URL, UIImageView *imageView, void (^completion)(void)) { + [self configImageView:imageView URL:URL completion:completion]; }]; [previewVc setDoneButtonClickBlock:^(NSArray *photos, BOOL isSelectOriginalPhoto) { self.isSelectOriginalPhoto = isSelectOriginalPhoto; @@ -126,6 +129,26 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa } } +- (void)configImageView:(UIImageView *)imageView URL:(NSURL *)URL completion:(void (^)(void))completion{ + if ([URL.absoluteString.lowercaseString hasSuffix:@"gif"]) { + // 先显示静态图占位 + [[SDWebImageManager sharedManager] loadImageWithURL:URL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { + if (!imageView.image) { + imageView.image = image; + } + }]; + // 动图加载完再覆盖掉 + [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:URL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) { + imageView.image = [UIImage sd_animatedGIFWithData:data]; + if (completion) { + completion(); + } + }]; + } else { + [imageView sd_setImageWithURL:URL]; + } +} + #pragma mark - TZImagePickerController - (TZImagePickerController *)createTZImagePickerController {