From f0f8bac823bdcfba78b57a6449e49c4eb410d120 Mon Sep 17 00:00:00 2001 From: llb <1422295521@qq.com> Date: Wed, 10 Jan 2018 16:32:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对预加载的图片的方式进行了优化和完善 --- test.xcodeproj/project.pbxproj | 3 + test/Class/style3/LBStyle3VC.m | 1 + test/LBPhotoBrowser/LBPhotoBrowserManager.h | 1 - test/LBPhotoBrowser/LBPhotoBrowserView.h | 1 - test/LBPhotoBrowser/LBPhotoBrowserView.m | 81 ++++++++++++--------- 5 files changed, 51 insertions(+), 36 deletions(-) diff --git a/test.xcodeproj/project.pbxproj b/test.xcodeproj/project.pbxproj index b07e121..03d2085 100644 --- a/test.xcodeproj/project.pbxproj +++ b/test.xcodeproj/project.pbxproj @@ -542,6 +542,7 @@ baseConfigurationReference = 52839D449824474097575972 /* Pods-test.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Manual; DEVELOPMENT_TEAM = ""; @@ -560,6 +561,7 @@ baseConfigurationReference = 7258DD35A57A1219D711F5E6 /* Pods-test.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Manual; DEVELOPMENT_TEAM = ""; @@ -568,6 +570,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.vcyber.test; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE_SPECIFIER = ""; }; name = Release; diff --git a/test/Class/style3/LBStyle3VC.m b/test/Class/style3/LBStyle3VC.m index 1c1cf36..b5d7fc8 100644 --- a/test/Class/style3/LBStyle3VC.m +++ b/test/Class/style3/LBStyle3VC.m @@ -66,6 +66,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N [[LBPhotoBrowserManager defaultManager] addPlaceholdImageCallBackBlock:^UIImage *(NSIndexPath *indexPath) { return [UIImage imageNamed:@"placehold.jpeg"]; }]; + }]; return cell; } diff --git a/test/LBPhotoBrowser/LBPhotoBrowserManager.h b/test/LBPhotoBrowser/LBPhotoBrowserManager.h index 556bafe..1090965 100644 --- a/test/LBPhotoBrowser/LBPhotoBrowserManager.h +++ b/test/LBPhotoBrowser/LBPhotoBrowserManager.h @@ -76,7 +76,6 @@ // 每张正在加载的图片的站位图的大小 @property (nonatomic , copy ,readonly)CGSize (^placeholdImageSizeBlock)(UIImage *Image,NSIndexPath *indexpath); - /** 开启这个选项后 在加载gif的时候 会大大的降低内存.与YYImage对gif的内存优化思路一样 default is NO 每次LBPhotoBrowser -> did dismiss(消失)的时候,LBPhotoBrowserManager 会将 lowGifMemory 置为NO, diff --git a/test/LBPhotoBrowser/LBPhotoBrowserView.h b/test/LBPhotoBrowser/LBPhotoBrowserView.h index eedaa8b..6fa87e7 100644 --- a/test/LBPhotoBrowser/LBPhotoBrowserView.h +++ b/test/LBPhotoBrowser/LBPhotoBrowserView.h @@ -31,7 +31,6 @@ @property (nonatomic , assign)BOOL isShowing; @property (nonatomic , assign)BOOL showPopAnimation; -@property (nonatomic , assign)BOOL shouldCancel; @property (nonatomic , assign)int index; @property (nonatomic , copy)void (^loadImageCompletedBlock)(LBScrollViewStatusModel *loadModel,UIImage *image, NSData *data, NSError * error, BOOL finished, NSURL *imageURL); diff --git a/test/LBPhotoBrowser/LBPhotoBrowserView.m b/test/LBPhotoBrowser/LBPhotoBrowserView.m index 5c56143..3ad8ee1 100644 --- a/test/LBPhotoBrowser/LBPhotoBrowserView.m +++ b/test/LBPhotoBrowser/LBPhotoBrowserView.m @@ -49,10 +49,12 @@ @interface LBPhotoBrowserView ()= 0 ?model.index - 1:0; int rightCellIndex = model.index + 1 < wself.models.count? model.index + 1 : (int)wself.models.count -1; - + //wself.loadingImageModels 新计算出的需要加载的 -- > 如果个原来的没有重合的 --> 取消 + [wself.preloadingModelDic removeAllObjects]; + NSMutableDictionary *indexDic = wself.preloadingModelDic; // 采用全局的字典 减少快速切换时 重复创建消耗性能的问题 + indexDic[[NSString stringWithFormat:@"%d",leftCellIndex]] = @1; + indexDic[[NSString stringWithFormat:@"%d",model.index]] = @1; + indexDic[[NSString stringWithFormat:@"%d",rightCellIndex]] = @1; + + for (NSString *indexStr in wself.loadingImageModelDic.allKeys) { + if (indexDic[indexStr]) continue; + LBScrollViewStatusModel *loadingModel = wself.loadingImageModelDic[indexStr]; + if (loadingModel.opreation) { + [loadingModel.opreation cancel]; + loadingModel.opreation = nil; + } + } + [wself.loadingImageModelDic removeAllObjects]; for (int i = leftCellIndex; i <= rightCellIndex; i++) { - model.shouldCancel = NO; + LBScrollViewStatusModel *loadingModel = wself.models[i]; + NSString *indexStr = [NSString stringWithFormat:@"%d",i]; + wself.loadingImageModelDic[indexStr] = loadingModel; if (model.index == i) continue; LBScrollViewStatusModel *preloadingModel = wself.models[i]; - preloadingModel.shouldCancel = NO; preloadingModel.currentPageImage = preloadingModel.currentPageImage ?:[wself getCacheImageForModel:preloadingModel]; if (preloadingModel.currentPageImage) continue; [preloadingModel loadImage]; } - - int finish = 0; - for (LBScrollViewStatusModel *obj in wself.models) { - if (obj.shouldCancel && obj.opreation) { - [obj.opreation cancel]; - obj.opreation = nil; - } - if (obj.currentPageImage) { - finish = finish + 1; - } - } - if (finish == wself.models.count) { - wself.stopPreloading = YES; - } }); + }