GithubHelp home page GithubHelp logo

imclab / olimageview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dtorres/olimageview

0.0 2.0 0.0 4.96 MB

Animated GIFs implemented the right way

License: MIT License

Objective-C 96.43% Ruby 3.57%

olimageview's Introduction

OLImageView (and OLImage)

Everybody loves a good GIF. Unfortunately, Apple's implementation of UIImage doesn't support animated GIFs. OLImage and OLImageView are drop-in replacements for UIImage and UIImageView with really good support for animated GIFs.

Why did we do this?

There are many other classes to do this already, but they just don't work the way they should. Most existing classes:

  • Divide the delay between frames evenly, all the time (even if the file specifies different per-frame delays)
  • Load frames synchronously, which freezes up the main thread (especially when loading large files) and only show anything when all the frames are loaded

We tried to fix some of these issues, but we found that the experience still didn't feel quite right. After a little of digging, we found out that browsers change the frame delays on certain conditions. This implementation adopts these conditions to provide an experience that is consistent with the WebKit rendering of an animated GIF.

How to use

Add the header and replace UIImageView with OLImageView.

Example

// Before (in your View Controller in this example)

- (void)loadView 
{
	[super loadView];
	self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,200,200)];
	[self.view addSubview:self.imageView];
}


// After

#import "OLImageView.h"

- (void)loadView 
{
	[super loadView];
	self.imageView = [[OLImageView alloc] initWithFrame:CGRectMake(0,0,200,200)];
	[self.view addSubview:self.imageView];
}

Now, when you create your image instances to put in the view, you should do it with the data.

Example

- (void)loadReceivedImageData:(NSData *)data;
{
	UIImage *image = [OLImage imageWithData:data];
	self.imageView.image = image;
}

##Integration with other libs ###AFNetworking This repo includes a category to integrate OLImage with AFNetworking v1.x UIImageView category, which provides caching and remote URL setters. To use this, just import the category where you will be using OLImageView with the AFNetworking category.

Users of AFNetworking 2.x can use any of the two provided image reponse serializers. OLImageResponseSerializer is a drop-in replacement for the standard AFNetworking serializer, which simply creates OLImage instances for every data:

imageView.imageResponseSerializer = [[OLImageResponseSerializer alloc] init];

Those who want to keep default AFImageResponseSerializer behavior or need to chain many serializers, there's a strict one, only accepting image/gif: OLImageStrictResponseSerializer. Serializer chaining might look like this:

imageView.imageResponseSerializer =
    [AFCompoundResponseSerializer compoundSerializerWithResponseSerializers:
        @[[[OLImageStrictResponseSerializer alloc] init], imageView.imageResponseSerializer]];

You are more than welcome to send pull requests with categories or subclasses that integrate OLImage with other libraries.

##Help us make this better Found a bug? A typo? Can you make the decoding faster? Feel free to fork this and send us a pull request (or file an issue).

olimageview's People

Contributors

dtorres avatar ejensen avatar karpelcevs avatar nickoneill avatar njuxjy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.