kikinteractive/SwiftyGif

Name: SwiftyGif

Owner: Kik Interactive

Description: High performance GIF engine

Forked from: kirualex/SwiftyGif

Created: 2016-06-23 08:34:40.0

Updated: 2017-05-21 17:34:06.0

Pushed: 2016-06-23 08:40:02.0

Homepage: null

Size: 73856

Language: Swift

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Language CocoaPods Compatible Carthage compatible Pod License

High performance & easy to use Gif engine

Features
Installation
With CocoaPods
ce 'https://github.com/CocoaPods/Specs.git'
frameworks!
'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:

gifmanager = SwiftyGifManager(memoryLimit:20)
gif = UIImage(gifName: "MyImage.gif")
imageview = UIImageView(gifImage: gif, manager: gifManager)
eview.frame = CGRect(x: 0.0, y: 5.0, width: 400.0, height: 200.0)
.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.

gifmanager = SwiftyGifManager(memoryLimit:20)
.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.

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.

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

SwiftyGif offer various controls on the current UIImageView playing your gif file.

.myImageView.startAnimatingGif()
.myImageView.stopAnimatingGif()
.myImageView.showFrameAtIndexDelta(delta: Int)
.myImageView.showFrameAtIndex(index: Int)

To allow easy use of those controls, some utility methods are provided :

.myImageView.isAnimatingGif() // Returns wether the gif is currently playing
.myImageView.gifImage!.framesCount() // Returns number of frames for this gif
Default Manager

If you only need to display one gif here and there, you can use the SwiftyGifManager.defaultManager which will use a SwiftyGifManager singleton with a default memory pool of 50Mb.

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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.