EGOImageView 解析 使用
来源:互联网 发布:玛格丽特小镇 知乎 编辑:程序博客网 时间:2024/06/06 00:25
在看EGOImageLoader源码的时候首先个人感觉要先理解里面的几个概念
1.inline 开头的函数表示内联函数。作用是用函数名直接代替表达式,也就是说执行到这一行代码的时候不会去调用函数,而是直接执行函数体。同样也有一定限制,那就是函数体不能太复杂,不能有循环和开关语句。最适合就是取值,而在EGOImageLoader这个框架中就是根据URL生成一个key返回。
inline static NSString* keyForURL(NSURL* url,NSString* style) {
if(style) {
return [NSStringstringWithFormat:@"EGOImageLoader-%u-%u", [[url description] hash], [style hash]];
} else {
return [NSStringstringWithFormat:@"EGOImageLoader-%u", [[url description] hash]];
}
}
********hash的作用是返回一个全局唯一的数字
2.需要了解的是EGO用的是观察者模式来回调函数,也就是说在调用imageForURL方法的时候会根据URL创建属于这个图片的专属通知,当加载完成后会发出通知,image会在notification的userinfo里面存着,并以object的形式伴随通知发过去。
****************************************************************
使用EGOImageView,
1.创建对象
imageView = [[EGOImageViewalloc] initWithPlaceholderImage:[UIImageimageNamed:@"placeholder.png"]];
imageView.frame = CGRectMake(4.0f, 4.0f, 36.0f, 36.0f);
[self.contentViewaddSubview:imageView];
2.把URL赋给imageURL这个属性
imageView.imageURL = [NSURLURLWithString:flickrPhoto];
3.在赋给这个属性的时候会自动调用属性的set方法,- (void)setImageURL:(NSURL *)aURL ;
在这个方法里,用注释的形式写出来
if(imageURL) {
//注销两个通知
[[EGOImageLoadersharedImageLoader] removeObserver:selfforURL:imageURL];
//引用计数减一并置空
[imageURLrelease];
imageURL = nil;
}
if(!aURL) {
//设置默认图片
self.image =self.placeholderImage;
imageURL = nil;
return;
} else {
//引用计数加一并且赋给imageURL
imageURL = [aURL retain];
}
[[EGOImageLoadersharedImageLoader] removeObserver:self];
//调用loader的方法来根据URL加载图片
UIImage* anImage = [[EGOImageLoader sharedImageLoader] imageForURL:aURL shouldLoadWithObserver:self];
//如果缓存有侧会立刻返回,如果缓存没有则会先设置默认图片,当加载图片完毕的时候会以通知的方法进行回调
if(anImage) {
self.image = anImage;
// trigger the delegate callback if the image was found in the cache
if([self.delegaterespondsToSelector:@selector(imageViewLoadedImage:)]) {
[self.delegateimageViewLoadedImage:self];
}
} else {
self.image =self.placeholderImage;
}
4.通知回调imageLoaderDidLoad这个方法
- (void)imageLoaderDidLoad:(NSNotification*)notification {
if(![[[notification userInfo]objectForKey:@"imageURL"] isEqual:self.imageURL]) return;
UIImage* anImage = [[notification userInfo] objectForKey:@"image"];
self.image = anImage;
//这个方法会调用drawrect的方法
[selfsetNeedsDisplay];
if([self.delegaterespondsToSelector:@selector(imageViewLoadedImage:)]) {
[self.delegateimageViewLoadedImage:self];
}
}
5.在这个类最重要的方法就是 [[EGOImageLoader sharedImageLoader] imageForURL:aURL shouldLoadWithObserver:self];
这个方法了,第一个是传URL,第二个是传观察者的对象。通过这个方法来加载图片,成功后会调用委托方法- (void)imageLoaderDidLoad:(NSNotification*)notification ;
- EGOImageView 解析 使用
- (转)EGOImageView 解析 使用
- egoimageview 使用2
- EGOImageView 使用方法
- EGOImageView与SDWebImage
- EGOImageView-缓存问题
- EGOImageView图片缓存加载
- EGOImageView的使用方法及注意事项
- 有关EGOImageView缓存的问题
- EGOImageView的使用方法及注意事项
- EGOImageView的使用方法及注意事项
- Low memory warning with several EGOImageView
- EGOImageView 滚动无法加在图片
- EGOImageView第三方库的应用
- 关于egoImageView类库的使用方法 和小技巧
- iPhone开发笔记(20)EGOImageView的使用方法及注意事项
- iOS 关于egoImageView类库的使用方法 和小技巧
- 关于egoImageView类库的使用方法 和小技巧
- WAP开发之SMS协议的用法
- poj 2196 [进制转换 各位求和]
- Linux下C语言编写基于命令行的FTP客户端与服务端
- android 电容屏(一):电容屏基本原理篇
- hibernate缓存机制
- EGOImageView 解析 使用
- 回首过去的那些事儿(11)
- RAC架构演变
- js、jquery、动态添加option项
- 一个很好的js网站工具查询
- android 电容屏(二):驱动调试之基本概念篇
- Android开发:ScrollView嵌套GridView的解决办法
- 定位表的最后操作时间
- 安装完Oracle数据库,给scott账户解锁方法