Web Image
=========
This library provides a category for UIImageVIew with support for remote images coming from the web.
It provides:
- An UIImageView category adding web image and cache management to the Cocoa Touch framework
- An asynchronous image downloader
- An asynchronous memory + disk image caching with automatic cache expiration handling
- A guarantee that the same URL won't be downloaded several times
- A guarantee that bogus URLs won't be retried again and again
- Performances!
Motivation
----------
As a dummy Objective-C developer working on my first iPhone application for my company
([Dailymotion][]), I've been very frustrated by the lack of support in the Cocoa Touch framework for
UITableView with remote images. After some Googling, I found lot of forums and blogs coming up with
their solution, most of the time based on asynchronous usage with NSURLConnection, but none provided
a simple library doing the work of async image grabbing + caching for you.
Actually there is one in the famous [Three20][] framework by [Joe Hewitt][], but it's a massive
and undocumented piece of code. You can't import just the the libraries you want without taking the
whole framework (damn #import "TTGlobal.h"). Anyway, the [Three20][] implementation is based on
NSURLConnection, and I soon discovered this solution wasn't ideal. Keep reading to find out why.
As a hurried beginner in iPhone development, I couldn't attempt to implement my own async image
grabber with caching support as my first steps in this new world. Thus, I asked for help from my good
friend Sebastien Flory ([Fraggle][]), who was working on his great iPhone game ([Urban Rivals][], a
future app-store hit) for almost a year. He spent quite an amount of time implementing the very
same solution for his needs, and was kind enough to give me his implementation for my own use. This
worked quite well and allowed me to concentrate on other parts of my application. But when I started
to compare my application with its direct competitor - the built-in Youtube application - I was very
unhappy with the loading speed of the images. After some network sniffing, I found that every HTTP
requests for my images was 10 times slower than Youtube's... On my own network, Youtube was 10
time faster than my own servers... WTF??
In fact, my servers were fine but a lot of latency was added to the requests, certainly because my
application wasn't responsive enough to handle the requests at full speed. Right then, I
understood something important, asynchronous NSURLConnections are tied to the main runloop in the
NSEventTrackingRunLoopMode. As explained in the documentation, this runloop mode is affected by
UI events:
> Cocoa uses this mode to restrict incoming events during mouse-dragging loops and other sorts of
> user interface tracking loops.
A simple test to recognize an application using NSURLConnection in its default mode to load
remote images is to scroll the UITableView with your finger to disclose an unloaded image, and to
keep your finger pressed on the screen. If the image doesn't load until you release you finger,
you've got one (try with the Facebook app for instance). It took me quite some time to understand
the reason for this lagging issue. Actually I first used NSOperation to workaround this issue.
This technique combined with an image cache instantly gave a lot of responsiveness to my app.
I thought this library could benefit other Cocoa Touch applications so I open-sourced it.
How To Use It
-------------
API documentation is available at [http://hackemist.com/SDWebImage/doc/](http://hackemist.com/SDWebImage/doc/)
### Using UIImageView+WebCache category with UITableView
Just #import the UIImageView+WebCache.h header, and call the setImageWithURL:placeholderImage:
method from the tableView:cellForRowAtIndexPath: UITableViewDataSource method. Everything will be
handled for you, from async downloads to caching management.
```objective-c
#import <SDWebImage/UIImageView+WebCache.h>
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] autorelease];
}
// Here we use the new provided setImageWithURL: method to load the web image
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
cell.textLabel.text = @"My Text";
return cell;
}
```
### Using blocks
If your project's deployement target is set to iOS 4+, you may want to use the success/failure blocks to be
notified when image have been retrieved from cache.
```objective-c
// Here we use the new provided setImageWithURL: method to load the web image
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
success:^(UIImage *image) {... success code here ...}
failure:^(NSError *error) {... failure code here ...}];
];
```
Note: neither your success nor failure block will be call if your image request is canceled before completion.
### Using SDWebImageManager
The SDWebImageManager is the class behind the UIImageView+WebCache category. It ties the
asynchronous downloader with the image cache store. You can use this class directly to benefit
from web image downloading with caching in another context than a UIView (ie: with Cocoa).
Here is a simple example of how to use SDWebImageManager:
```objective-c
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:imageURL
delegate:self
options:0
success:^(UIImage *image)
{
// do something with image
}
failure:nil];
```
### Using Asynchronous Image Downloader Independently
It is possible to use the async image downloader independently. You just have to create an instance
of SDWebImageDownloader using its convenience constructor downloaderWithURL:delegate:.
```objective-c
downloader = [SDWebImageDownloader downloaderWithURL:url delegate:self];
```
The download will start immediately and the imageDownloader:didFinishWithImage: method from the
SDWebImageDownloaderDelegate protocol will be called as soon as the download of image is completed.
### Using Asynchronous Image Caching Independently
It is also possible to use the NSOperation based image cache store independently. SDImageCache
maintains a memory cache and an optional disk cache. Disk cache write operations are performed
asynchronous so it doesn't add unnecessary latency to the UI.
The SDImageCache class provides a singleton instance for convenience but you can create your own
instance if you want to create separated cache namespace.
To lookup the cache, you use the imageForKey: method. If the method returns nil, it means the cache
doesn't currently own the image. You are thus responsible for generating and caching it. The cache
key is an application unique identifier for the image to cache. It is generally the absolute URL of
the image.
```objective-c
UIImage *myCachedImage = [[SDImageCache sharedImageCache] imageFromKey:myCacheKey];
```
By default SDImageCache will lookup the disk cache if an image can't be found in the memory cache.
You can prevent this from happening by calling the alternative method imageFromKey:fromDisk: with a
negative second argument.
To store an image into the cache, you use the storeImage:forKey: method:
```objective-c
[[SDImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey];
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
ios 一个不错的图片浏览分享框架demo 。iphone 6.1测试通过。框架适合图片浏览,并可以微博分享到新浪,腾讯,网易等(由于各个微博接口有调整,不一定能分享成功。只看框架,分享功能可以找最新的官方接口整合)。demo说明和截图可以到http://blog.csdn.net/donny_zhang 查看。
资源推荐
资源详情
资源评论
收起资源包目录
ios 一个不错的图片浏览分享框架demo (528个子文件)
03478aad18bcd5949c849df88a355649ab177e 689B
086034d4fd44bc967c05137d1ef84f7d58d01b 406B
08e9cec3d35251eb83eb4a59f43dec2edaab02 269B
094ee360d880fd86998a3eec343be642121b76 250B
096cd1da63bc01640c872a326f209a78e15112 1KB
09b8416695b60eab3d850613d2947779932f33 298B
0a60501262a5a7150d852292b70a63e59d620b 485B
0b8b292afc5d62fe3d6dcad3d77b287bc66479 199B
0c309a591e52616e6919abf09d6027b8246d16 201B
0c88a60ed600de4fd586a708e001f4ec30c63d 127B
0e69f8e444b6e3962f259c88cf63619ddfa3b6 87B
111b0cd9001493501f0d734706abe93211f988 328B
1522be86394bfad37d1cf77a385f789f3533cb 171B
1726e911d8672c350c8a76bfe3bde022904ba9 2KB
17bee4e45042079493ef6d18bde827582777a5 4KB
195b1c704ca389f1c6515866363d4d43db6253 892B
19a7a189e10e649defe6013bc9c9ce04bed4c3 7KB
19eaa01a60e522a41e4ef2a5bc2f450fb1d0a4 334B
1ca8be8189c6a3130af264e3e15d568fd9d6e4 1KB
1d4ac342fee385942b4d2580449ed91e388c52 1KB
1f014863ad82daaded186bec36ce4412c94421 4KB
20ad8b9e28393045fe985a285002e5c845a8da 910B
23ca177e4979d93016434e3896ba093ed47b65 2KB
23f88f5893fdc5fee76f52da2dedd7caad25de 766B
27a176a45c32a4fb0c83ee669d26c61c8539a2 766B
2fae084ff28253948f92c39b4d4004160d12f3 674B
3348e33fa847173511b6e6c167adf339b212d9 1KB
335ea47102bb3dcb20f10d86d87de48c1e9287 175B
3368e95ba6742bf1adac163c862c126c1b072e 7KB
336c5b5a3753d6d6ffd352cfaef30f17d82028 227B
3372ca012c0d92297402c50a9c6481730260f3 265B
338b227e415f051407d5deae6d7befa55e3bcc 212B
36dbee1e79ccdf0ebcb5b2263db180e4b22c34 164B
37597b848a1890bb30ba0ff4102f8107cafdcb 61B
37be7f04e1d08ead9faaef4dfdf62c2e59210d 815B
3a13929480a06a477d82f74d42035cdeb1f0fd 231B
3c4e08bdbdfcb450d6d68e520a812f8533e0da 620B
3d2dbcf29166f0f18f0b29a34cd2206df3a469 261B
3e29a0a8739ec94c8e48e02fd5a79486b296de 6KB
3e854eb9134acdbcfe0f82444da03d4f52c35e 3KB
3f83cb0b93434f1272a44eb6df4786eab3ebc9 82B
3f85244a179a7665d223aed6a7d610a947716f 6KB
4000a302691e6eb7558386352ec18c9bae1153 179B
405f0534affe8840a0ef88a4feaeb3965a7175 333B
41d1dcf6c443b19578715df7f9927224e3396a 6KB
424a94b57fc184166ab24b1ce18bdebf7e3553 528B
49a5a8dd73de7c1e28fddd80631d0f44772fa4 135B
4cda0835096ed4b1b1a26847f3c4096ee66304 128B
5027d0ab86b27069d8e14580873ab1870f9104 131B
50fdd1c44d9547a291d4add9de13f1df2040bd 1KB
516f1a67060ad9c177fec42fb0d28d63b8c589 293B
5304d5de8e20588c23868ba3e5b9f43483bfc5 127B
5bc61162ff38b742ff5ca7bceb3e1cde74ced0 3KB
5e1815e10323e2f2b45c04765716bf8bdcbbc1 3KB
60e229bd1f9ba56c91f7c01c08c498e8b1e0ef 250B
6427ac8b12250e15bcdfaed2239fd7128f499e 1KB
67997895ed5dc83dd593668dcebab60ecb283a 522B
697057e79e27363a08306bb706410e31059f92 45B
6af03e31f591de77a2f734c1358129d89e1d46 307B
6be01fa440a875a30d969311fc9509c4ea2152 702B
6be38ad30f2c8ae86161808908bec681dd32af 208B
6d1542ecac6ca9203d0e920d1a18dc2f2146be 407B
6d86b33dfeef743884540e1bf5867bdbd87e52 120B
70fd93ac5238f3892ce69d5d32d096bc055798 1KB
7534012ead78f1ac434f6f1a561c6a07f28e23 2KB
76a7bae2c27818041bcb6d4783a95dc08e2271 318B
783e175de80cc4846ce0ad679e845ce6f083d8 666B
7849f59cc6a49cedd2ba2b768397c6bc235f00 57B
789dd75886143435e0757719825031537c338a 158B
7b28ff8f86a3158a71c4934fbd3a2456717d7a 61B
7bff477984fc9ae2e242d31899fe364396053c 547B
7edba4e138cbc0ee38a6b46a8e02589e238355 5KB
84ca64d971a8ac99fc609cddb698c941beecee 199B
85d502929c955b6e746c48ad4b29973708e964 208B
8600f82c7241875ef4108db5e98b5e5c8e8a22 119B
86eb75ebdce30bb36b253a6ba16da2dea0de38 25KB
8a165aebd6fa10e2ea0c13dc6082237a1d375b 258B
8c9eb0949cfef1e5c0de17934d6c0bc95cff7f 3KB
8ca6f693f96d511e9113c0eb59eec552354e42 2KB
8cc1ee2d10b41ce236b208757731c5548ed50c 155B
8dab9994eaa18d798af73c9c95db27692c5afb 1KB
8fe884edb0f75dba9613a6e111954f5e53ec33 341B
9064b8f9cc01f0222253b6933244f940ae6308 261B
9123453c6b838906cda06e8c8c8dba95124685 212B
91b7aabfcf3422423b109c8beed2bab838c607 2KB
9302f7f3633bb98ca2614fb0cb13d50dc5c2a3 148B
931bed94ab9d8173ef2902a27085171095e0a0 457B
946060790cbe5e8dd3cc80887b823a94b8e46b 355B
94c916a73b2b12eb1a875f73aaec8732e49460 4KB
95f57073ffb8f3b080b1c281aadfdd68c4a4a0 711B
97ee396cbcb222d2981b17df80c836cb9a064b 1KB
9e015345d82cfcaa969f0977a05a7157104a2c 2KB
9f25efa265e70185a057018d5cb82f99766fc0 996B
9f2de25ab19385cab02b8053194af2ec975284 236B
libWeChatSDK_armv7_armv7s.a 842KB
a0c069bc0b38f5010b588be0b3ece6b82fc9a8 827B
a1a4601b16086d9849d104610e8e8edac222a1 399B
a581cc132a015f0c0b7f80edaedd973544e5ea 270B
a6f112173a061806942734a8764c1e13b117b7 542B
a8df0987ed1e114e8a39b1212fd68b14c74799 828B
共 528 条
- 1
- 2
- 3
- 4
- 5
- 6
Donny_zhang
- 粉丝: 61
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页