Latest4.1.0
Homepagehttps://github.com/kirualex/SwiftyGif
LicenseMIT
Platformsios 8.0, requires ARC
Authors

Language
CocoaPods Compatible
Carthage compatible
Pod License
Build Status

High performance & easy to use Gif engine

SwiftyGif SwiftyGif

Features

  • [x] UIImage and UIImageView extension based
  • [x] Remote Gifs
  • [x] Great CPU/Memory performances
  • [x] Control playback
  • [x] Allow control of display quality by using ‘levelOfIntegrity’
  • [x] 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.

Quick Start

SwiftyGif uses familiar UIImage and UIImageView to display gifs.

import SwiftyGif

let gif = UIImage(gifName: "MyImage.gif")
let imageview = UIImageView(gifImage: gif, loopCount: 3) // Use -1 for infinite loop
imageview.frame = view.bounds
view.addSubview(imageview)

In case your UIImageView is already created (via Nib or Storyboards for instance), it’s even easier.

self.myImageView.setGifImage(gif) 

// You can also set it with an URL pointing to your gif
let url = URL(string: "...")
self.myImageView.setGifFromURL(url) 

Performances

A SwiftyGifManager can hold one or several UIImageView using the same memory pool. This allows you to tune the memory limits to you convenience. If no manager is declared, SwiftyGif will just use the SwiftyGifManager.defaultManager.

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)

Controls

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

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

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

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

Delegate

You can declare a SwiftyGifDelegate to receive updates on the gif lifecycle.
For instance, if you want your controller MyController to act as the delegate:

override func viewDidLoad() {
        super.viewDidLoad()
        self.imageView.delegate = self
}

Then simply add an extension:

extension MyController : SwiftyGifDelegate {

    func gifURLDidFinish(sender: UIImageView) {
        print("gifURLDidFinish")
    }

    func gifURLDidFail(sender: UIImageView) {
        print("gifURLDidFail")
    }

    func gifDidStart(sender: UIImageView) {
        print("gifDidStart")
    }

    func gifDidLoop(sender: UIImageView) {
        print("gifDidLoop")
    }

    func gifDidStop(sender: UIImageView) {
        print("gifDidStop")
    }
}

Benchmark

Display 1 Image

CPU Usage(average)Memory Usage(average)
FLAnimatedImage35%9,5Mb
SwiftyGif2%18,4Mb
SwiftyGif(memoryLimit:10)34%9,5Mb

Display 6 Images

CPU Usage(average)Memory Usage(average)
FLAnimatedImage65%25,1Mb
SwiftyGif22%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.

Latest podspec

{
    "name": "SwiftyGif",
    "version": "4.1.0",
    "summary": "High performance Gif engine in Swift. Add and control Gif images easily!",
    "homepage": "https://github.com/kirualex/SwiftyGif",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Alexis Creuzot": "[email protected]"
    },
    "source": {
        "git": "https://github.com/kirualex/SwiftyGif.git",
        "tag": "4.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "SwiftyGif/*{.h,.swift}",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This