Open Source framework: Sdwebimage

Source: Internet
Author: User

http://blog.csdn.net/uxyheaven/article/details/7909373

Sdwebimage is one of the few frames I've admired since iOS, worshipping the author. It's really great!

This open source framework is also quite important, involving the asynchronous loading of picture sources and automatic caching.

If we can skillfully use its API, we can achieve a lot of complex requirements.

The author is still updating, the 3.0 version is already very powerful! simplifies more API interfaces. Enhanced download class, support for multiple files simultaneously download, built-in download progress function.

GitHub escrow addresses are as follows:

Https://github.com/rs/SDWebImage

Sdwebimage API documentation Entrance (English, egg ache, if Chinese, I guess we also do not write this article, or also very short.):

http://hackemist.com/SDWebImage/doc/

If you just download a framework in a hurry and go back to your project, you may encounter an unusable situation: then the following article solves the problem you are experiencing:

http://blog.csdn.net/qjlhlh/article/details/8191111

It's a good idea to look at the Readme in advance when using this type of code (instructions for use) .

1: Introduce system framework imageio.framework.

2:framework introduces the header file in the following way:

[CSharp]View Plaincopy
    1. #import <SDWebImage/UIImageView+WebCache.h>

3:build settings->other Linker flags->-objc or-all_load

After three sets, you can start writing code.

The following is a description of the various class library functions that are used:

Sdwebimagedownloader

This version of the downloader is very large, now in one way, is to launch the function to download the image:

[CSharp]View Plaincopy
    1. [[Sdwebimagedownloader Shareddownloader] downloadimagewithurl:imageurl options: Sdwebimagedownloaderprogressivedownload progress:^ (Nsuinteger receivedsize, long long expectedsize) {
    2. NSLog (@"%u%lld", receivedsize,expectedsize);
    3. } completed:^ (UIImage *aimage, NSData *data, Nserror *error, BOOL finished) {
    4. //self.image = aimage;
    5. NSLog (@"succeeded:%d", UIImageJPEGRepresentation (Aimage, 1). length);
    6. }];

Most of the parameters in the inside of a look to understand, progress block returned information has two parameters: 1: Download progress. 2: File size.

I'll explain here what the options enumeration does.

Sdwebimagedownloaderoptions

1:sdwebimagedownloaderlowpriority this belongs to the default usage mode, go to download, return progress block information, call Completedblock when finished

2:sdwebimagedownloaderprogressivedownload This is a new version of the added features, after the setting, in the return to the progress of block, return to Completedblock, inside the uiimage is the current download of the picture, Can be implemented to display the image a little bit of functionality.

The hardest thing in the world is understanding! Open a joke ^ ^

Then Sdwebimagedownloader in the new version of the Division of labor is very clear, only do one thing, that is download, just download, so, after the successful download of the image resources will not be automatically cached.

If you want to cache, you need to use this

Sdimagecache

Sdimagecachetype This enumeration tells the source of the image at the end of the immediate download request

1:sdimagecachetypenone Network

2:sdimagecachetypedisk Device Hard Drive

3:sdimagecachetypememory Memory

Combine the requirements of the above two steps to use directly

Sdwebimagemanager

Changes to the new version of the management class are also quite large, and in one way, as follows:

[CSharp]View Plaincopy
    1. [[Sdwebimagemanager Sharedmanager] Downloadwithurl:imageurl options:sdwebimagelowpriority progress:^ (NSUInteger Receivedsize, long long expectedsize) {
    2. NSLog (@"%u%lld", receivedsize,expectedsize);
    3. } completed:^ (UIImage *aimage, Nserror *error, Sdimagecachetype CacheType, BOOL finished) {
    4. Self.image = Aimage;
    5. NSLog (@"succeeded:%d", UIImageJPEGRepresentation (Aimage, 1). length);
    6. }];


This initiates a download request that automatically caches the picture resource.

Then any originating download request will return an agent. This is a magical writing, worth a dig.

That is:sdwebimageoperation to cache this delegate, what to do with it? One thing, cancel the download request.

This article describes the whole sdwebimage operation principle, after you read, will certainly say: really TMD complex

http://blog.csdn.net/uxyheaven/article/details/7909373

Open Source framework: Sdwebimage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.