[MISSAJJ原创]cell内 通过SDWebImage自定义创建动态菊花加载指示器
最后更新已经放到了github上了
MISSAJJ自己写的一个基于SDWebImage自定义的管理网络图片加载的工具类(普通图片加载,渐现Alpha图片加载,菊花Indicator动画加载)
经常在项目里要用到SDWebImage的类来异步加载图片,于是考虑用代码分层的理念和方案,单独写了一个MAImageViewTool工具类用于调用SDWebImage异步加载图片,后期如果项目需要修改就只需要在这个工具类里改写和调试,不用在整个项目里批量寻找再一段一段改写代码了,提高了效率。
在这个类里增加了渐现Alpha图片加载和菊花Indicator动画加载的效果,有需要的攻城狮可以用来看看效果。
https://github.com/MISSAJJ/MAImageViewTool
/**
* cell内 普通图片加载 */ [cell.imageView sd_setImageWithURL:[NSURL URLWithString:imageToLoad] placeholderImage: [UIImage imageNamed:EMPTY_IMAGE]]; /**
* cell内 自定义创建图片动态加载指示器 */ __block UIActivityIndicatorView * indicatorPlaceholder; [cell.imageView sd_setImageWithURL:[NSURL URLWithString:imageToLoad] placeholderImage:nil options:SDWebImageCacheMemoryOnly progress:^(NSInteger receivedSize, NSInteger expectedSize) { //创建指示器:必须放在线程内才不会报错 dispatch_async(dispatch_get_main_queue(), ^{ if(!indicatorPlaceholder){ [cell.imageView addSubview:indicatorPlaceholder = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]]; indicatorPlaceholder.center = cell.imageView.center; [indicatorPlaceholder startAnimating]; } }); } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { //如果图片未缓存 渐现效果 if (cacheType == SDImageCacheTypeNone) { cell.imageView.alpha = 0.5; [UIView animateWithDuration:1.0 animations:^{ cell.imageView.alpha = 1.0; }]; } // 消除指示器 这种删除比较彻底
for (UIView * view in [cell.imageView subviews]) {
if ([view isKindOfClass:[UIActivityIndicatorView class]]) {
[view removeFromSuperview];
}
}
//这种删除方法会有bug,清楚缓存后重载,某些cell上还是会有菊花
//if (indicatorPlaceholder) { //[indicatorPlaceholder removeFromSuperview]; //indicatorPlaceholder = nil; //} }];
[MISSAJJ原创]cell内 通过SDWebImage自定义创建动态菊花加载指示器的更多相关文章
- 使用SDWebImage淡入淡出的方式加载图片
使用SDWebImage淡入淡出的方式加载图片 效果: 请通过以下方式下载源码: 找到它修改文件的地方: 以下是使用源码: // // ViewController.m // SDWebImageFa ...
- 自定义progressDialog(数据加载框)的实现
大家在开发客户端时基本上都需要获取数据,在获取数据时会有一个等待状态,这时我们可以利用系统自带的progressDialog来向用户展示"数据正在加载中..."等等,但有时我们会觉 ...
- 使用谷歌提供的SwipeRefreshLayout下拉控件,并自定义实现下拉加载的功能
package com.loaderman.swiperefreshdemo; import android.os.Bundle; import android.os.Handler; import ...
- 2.3 spring5源码系列---内置的后置处理器PostProcess加载源码
本文涉及主题 1. BeanFactoryPostProcessor调用过程源码剖析 2. 配置类的解析过程源码 3. 配置类@Configuration加与不加的区别 4. 重复beanName的覆 ...
- Spring源码之IOC容器创建、BeanDefinition加载和注册和IOC容器依赖注入
总结 在SpringApplication#createApplicationContext()执行时创建IOC容器,默认DefaultListableBeanFactory 在AbstractApp ...
- 在Unity中创建可远程加载的.unity3d包
在一个Unity项目中,发布包本身不一定要包括所有的Asset(译为资产或组件),其它的部分可以单独发布为.unity3d,再由程序从本地/远程加载执行,这部分不在本文讨论范围.虽然Unity并没有直 ...
- javascript动态创建script标签,加载完成后调用回调
代码如下: var head = document.getElementsByTagName('head')[0]; var script = document.createElement('scri ...
- 自定义的插件如何加载到Qt Designer中(详细)
要想在Qt Designer中使用自定义控件,必须要使Qt Designer能够知道我们的自定义控件的存在.有两种方法可以把新自定义控件的信息通知给Qt Designer:“升级(promotion) ...
- xcode UIImageView创建、图片加载、 音频文件播放、 延迟调用
代码创建 /** 创建UIImageView */ UIImageView * imageView=[[UIImageView alloc]init]; /** 设置尺寸位置 */ imageView ...
随机推荐
- 个人项目制作(PSP)
计划: 软件的此功能的实现,个人估算需要一个周的时间. 开发阶段: 需求分析: 1> 运动员希望软件可以记录自己的得分项. 2> 运动员希望软件可以记录自己的得分具体细节. 3>运动 ...
- LAMP环境搭建 (原创帖,转载请注明出处)
=============================说在前面的话==========================第一安装Mysql第二安装Apache-httpd第三安装PHP 第四配置PH ...
- mac上eclipse用gdb调试(转)
mac上eclipse用gdb调试 With its new OS release, Apple has discontinued the use of GDB in OS X. Since 2005 ...
- ionic imgBase64
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: , destinationType: destinationTyp ...
- asp.net天网代码
自己整理的asp.net中国天气网的城市代码 完整下载 case "北京": Code = "101010100"; break; case "海淀& ...
- virtualbox安装增强功能时【未能加载虚拟光盘】
virtualbox安装增强功能时[未能加载虚拟光盘] 今天在使用Virtualbox中的Ubuntu虚拟机,想安装增强功能来实现更改分辨率,但是在安装时出错:未能加载虚拟光驱 VBoxsGuestA ...
- OpenLayers控制瓦片的绽放级别
先说说这个功能可能使用到的地方,当我们下载的网上瓦片或者矢量数据的第一级或开始几级效果不是很好时,我们就就想让用户看到这些级别的瓦片.实现这个功能比较简单,主要就是修改Openlayers.map的i ...
- 通过nginx代理之后,获取客户端ip
1.相关nginx配置(通过header将客户端ip,host等信息传入) location ~ .*.do$ { proxy_set_header X-Real-IP $remote_addr; p ...
- Example For maven-compiler-plugin
1. Compiling Sources Using A Different JDK The compilerVersion parameter can be used to specify the ...
- [Amazon] Amazon IAP for Unity
1> 下载amazon IAP3.0 for unity plugin 2> 根据 https://developer.amazon.com/public/apis/earn/in-app ...