XHWebImageAutoSize
-网络图片尺寸适配解决方案
1.iOS开发中,常碰到网络图片需要做尺寸适配(使显示出来的图片不变形)
2.最好的解决方案是:后端把图片的分辨率拼接在图片的URL地址中,我们截取获得分辨率,从而根据宽高比,来适配imageView尺寸.
3.但当后端所给图片URL地址中没有分辨率,他又不肯加时,只好我们自己来解决了.
4.XHWebImageAutoSize就是解决3中的这种情况.
5.代码地址:https://github.com/CoderZhuXH/XHWebImageAutoSize
==============
前言:1.iOS开发中,常碰到网络图片需要做尺寸适配(使显示出来的图片不变形)
2.最好的解决方案是:后端把图片的分辨率拼接在图片的URL地址中,我们截取获得分辨率,从而根据宽高比,来适配imageView尺寸.
3.但当后端所给图片URL地址中没有分辨率,他又不肯加时,只好我们自己来解决了.
4.XHWebImageAutoSize就是解决3中的这种情况.
特性:1.异步缓存网络图片尺寸,优先从缓存中获取图片尺寸.
2.UITableView,UICollectionView UI动态更新.
技术交流群(群号:537476189).更新记录:2016.11.21 -- v1.0
效果
1.获取图片高度/尺寸及缓存相关
/** * Get image height * * @param url imageURL * @param layoutWidth layoutWidth * @param estimateHeight estimateHeight(default 100) * * @return imageHeight */ +(CGFloat)imageHeightForURL:(NSURL *)url layoutWidth:(CGFloat)layoutWidth estimateHeight:(CGFloat )estimateHeight; /** * Get image size from cache,query the disk cache synchronously after checking the memory cache * * @param url imageURL * * @return imageSize */ +(CGSize )imageSizeFromCacheForURL:(NSURL *)url; /** * Store an imageSize into memory and disk cache * * @param image image * @param url imageURL * @param completedBlock An block that should be executed after the imageSize has been saved (optional) */ +(void)storeImageSize:(UIImage *)image forURL:(NSURL *)url completed:(XHWebImageAutoSizeCacheCompletionBlock)completedBlock; /** * Get reload state from cache,query the disk cache synchronously after checking the memory cache * * @param url imageURL * * @return reloadState */ +(BOOL)reloadStateFromCacheForURL:(NSURL *)url; /** * Store an reloadState into memory and disk cache * * @param state reloadState * @param url imageURL * @param completedBlock An block that should be executed after the reloadState has been saved (optional) */ +(void)storeReloadState:(BOOL)state forURL:(NSURL *)url completed:(XHWebImageAutoSizeCacheCompletionBlock)completedBlock;2.tableView reload相关
/** * Reload row * * @param indexPath indexPath * @param url imageURL */ -(void)xh_reloadRowAtIndexPath:(NSIndexPath *)indexPath forURL:(NSURL *)url; /** * Reload row withRowAnimation * * @param indexPath indexPath * @param animation UITableViewRowAnimation * @param url imageURL */ -(void)xh_reloadRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation forURL:(NSURL *)url;#p#分页标题#e#
3.collectionView reload相关
/** * Reload item * * @param indexPath indexPath * @param url imageURL */ -(void)xh_reloadItemAtIndexPath:(NSIndexPath *)indexPath forURL:(NSURL *)url; 安装1.手动添加:1.将 XHWebImageAutoSize 文件夹添加到工程目录中
2.导入 XHWebImageAutoSize.h
2.CocoaPods:1.在 Podfile 中添加 pod 'XHWebImageAutoSize'
2.执行 pod install 或 pod update
3.导入 XHWebImageAutoSize.h
Tips1.如果发现pod search XHWebImageAutoSize 查询出来的不是最新版本,开题报告,需要在终端执行cd ~/desktop退回到desktop,然后执行pod setup命令更新本地spec缓存(需要几分钟),开题报告,然后再查询就可以了
2.如果你发现你执行pod install后,导入的不是最新版本,请删除Podfile.lock文件,在执行一次 pod install
3.如果在使用过程中遇到BUG,希望你能Issues我,谢谢(或者尝试下载最新的代码看看BUG修复没有)
系统要求该项目最低支持 iOS 7.0 和 Xcode 7.0
许可证XHWebImageAutoSize 使用 MIT 许可证,详情见 LICENSE 文件