Code Monkey home page Code Monkey logo

swiftygif's Introduction

Language CocoaPods Compatible Carthage compatible Pod License

High performance Gif engine based on JWAnimatedImage

video

##Features

  • UIImage and UIImageView extension based
  • Great CPU/Memory performances
  • Allow control of display quality by using 'levelOfIntegrity'
  • Allow control CPU/memory tradeoff via 'memoryLimit'

##Installation ######With CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
pod 'SwiftyGif'

##How to Use ####Project files As of now, Xcode xcassets folders do not recognize .gif as images. This means you need to put your .gif oustide of the assets. I recommend creating a group gif for instance.

####Init To use SwiftyGif you need 3 components:

  • An UIImage which backs the gif data and cache it for efficient use.
  • An UIImageView which hold to the UIImage gif and provide utility methods.
  • A SwiftyGifManager which can hold one or several UIImageView using the same memory pool.
let gifmanager = SwiftyGifManager(memoryLimit:20)
let gif = UIImage(gifName: "MyImage.gif")
let imageview = UIImageView(gifImage: gif, manager: gifManager)
imageview.frame = CGRect(x: 0.0, y: 5.0, width: 400.0, height: 200.0)
view.addSubview(imageview)

####Set In case your UIImageView is already created (via Nib or Storyboards for instance), you can also set its Gif. You can do this multiple times, new parameters overwrite old ones.

let gifmanager = SwiftyGifManager(memoryLimit:20)
self.myImageView.setGifImage(gif, manager: gifManager) 

####Level of integrity Setting a lower level of integrity will allow for frame skipping, lowering both CPU and memory usage. This can be a godd option if you need to preview a lot of gifs at the same time.

let gif = UIImage(gifName: "MyImage.gif", levelOfIntegrity:0.5)

####LoopCount You can furthermore set a specific number of loops to your gif via loopCount. Default is -1, which translate to infinite.

self.myImageView.setGifImage(gif, manager: gifManager, loopCount:2)// The gif will loop 2 times

####Default Manager If you only need to display one gif here and there, you can omit the manager parameter on UIImageView methods. By default, it will use the SwiftyGifManager.defaultManager with a default memory pool of 20Mb.

##Benchmark ####Display 1 Image

CPU Usage(average) Memory Usage(average)
FLAnimatedImage 35% 9,5Mb
SwiftyGif 2% 18,4Mb
SwiftyGif(memoryLimit:10) 34% 9,5Mb

####Display 6 Images

CPU Usage(average) Memory Usage(average)
FLAnimatedImage 65% 25,1Mb
SwiftyGif 22% 105Mb
SwiftyGif(memoryLimit:20) 45% 26Mb

Measured on an iPhone 6S, iOS 9.3.1 and Xcode 7.3.

##Licence SwiftyGif is released under the MIT license. See LICENSE for details.

swiftygif's People

Contributors

alexiscreuzot avatar jlnquere avatar

Watchers

Carabineiro 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.