The yywebimage of iOS learning replaces sdwebimage

Source: Internet
Author: User
Tags webp


Yywebimage is an asynchronous picture-loading framework (one of the Yykit components).



SOURCE Address: Click on the Open link



Designed to replace open source frameworks such as Sdwebimage, Pinremoteimage, and Flanimatedimage, it supports most of the features of these open source frameworks, while adding a lot of new features and performance enhancements.



It realizes the memory and the disk cache with Yycache, and realizes the decoding and playback of the Webp/apng/gif motion diagram with Yyimage.
You can view these items for more information.

  attributes 

asynchronous picture loading, which supports HTTP and local files. Supports GIF, apng, WebP animations (dynamic caching, low memory footprint). Supports progressive scan, interlaced scanning, progressive image loading. Category method support for Uiimageview, UIButton, Mkannotationview, Calayer. Common picture processing: blur, fillet, resize, cut, rotate, hue, etc. High-performance memory and disk caching. High-performance image settings to avoid blocking the main thread. Each class and method has a sound documentation comment. 

usage load a picture from a URL


Load network picture
Imageview.yy_imageurl = [Nsurl urlwithstring:@ "Http://github.com/logo.png"];

Load local picture
Imageview.yy_imageurl = [Nsurl fileurlwithpath:@ "/tmp/logo.png"];
load-Moving diagram
You just have to replace ' uiimageview ' with ' Yyanimatedimageview '.
Uiimageview *imageview = [Yyanimatedimageview new];
Imageview.yy_imageurl = [Nsurl urlwithstring:@ "HTTP://GITHUB.COM/ANI.WEBP"];
Incremental Picture Loading
Progressive: Edge Download side display
[ImageView yy_setimagewithurl:url options:yywebimageoptionprogressive];

Incremental loading, adding blur effects and gradient animations (see the GIF demo at the top of this page)
[ImageView yy_setimagewithurl:url Options:yywebimageoptionprogressiveblur | Yywebimageoptionsetimagewithfadeanimation];
loading and processing pictures
1. Download pictures
//2. Get Picture Download Progress
//3. Resize picture, add fillet
//4. Add a fade animation to the picture to get a better user experience

[ImageView Yy_setimagewithurl:url
    placeholder:nil
    options:yywebimageoptionsetimagewithfadeanimation
    progress:^ (nsinteger Receivedsize, Nsinteger expectedsize) {
        progress = (float) receivedsize/expectedsize;
    }
    Transform:^uiimage * (UIImage *image, Nsurl *url) {
        image = [Image yy_imagebyresizetosize:cgsizemake (100, 100) Contentmode:uiviewcontentmodecenter];
        return [Image yy_imagebyroundcornerradius:10];
    }
    completion:^ (UIImage *image, Nsurl *url, Yywebimagefromtype from, Yywebimagestage stage, Nserror *error) {
        if (from = = Yywebimagefromdiskcache) {
            NSLog (@ "Load from disk Cache");
        }
    ];
Picture Caching
Yyimagecache *cache = [Yywebimagemanager sharedmanager].cache;

Gets the cache size
cache.memoryCache.totalCost;
Cache.memoryCache.totalCount;
Cache.diskCache.totalCost;
Cache.diskCache.totalCount;

Empty Cache
[Cache.memorycache removeallobjects];
[Cache.diskcache removeallobjects];

Empty disk cache, with progress callback
[Cache.diskcache removeallobjectswithprogressblock:^ (int removedcount, int totalcount) {
    // Progress
} endblock:^ (BOOL error) {
    //End
}];

installation Cocoapods

Update Cocoapods to the latest version. Add pod ' yywebimage ' to podfile. Perform pod install or pod update. Import <YYWebImage/YYWebImage.h>. Note: The pod configuration does not contain WebP components, and if you need to support WebP, you can add pod ' yyimage/webp ' to podfile. You can call Yyimagewebpavailable () to check if the WebP component is properly installed.

  Carthage

Add GitHub "Ibireme/yywebimage" to the cartfile. Perform Carthage update--platform iOS and add the generated framework to your project. Import <YYWebImage/YYWebImage.h>. Note: The Carthage Framework does not contain WEBP components. If you need to support WebP, you can install it with cocoapods or manually. 

Manual Installation

Download all content in the Yywebimage folder. Add (drag and drop) the source files within the Yywebimage to your project. Link the following frameworks:uikit corefoundation quartzcore assetslibrary ImageIO accelerate the mobilecoreservices sqlite3 libz import YYWeb Image.h. Note: If you need to support WebP, you can add vendor/webp.framework (static library) to your project. You can call Yyimagewebpavailable () to check if the WebP component is properly installed.

Related Article

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.