Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.
/ gif Public archive

Animated GIF in UIImage

License

Notifications You must be signed in to change notification settings

toddheasley/gif

Repository files navigation

AnimatedGIF

Extends UIImage to support GIF animation

Requirements

Targets iOS/iPadOS/tvOS 14. Written in Swift 5.3 and requires Xcode 12 or newer to build.

Example Usage

The added factory UIImage.animatedImage(data: Data) can be used as a replacement for UIImage(data: Data) where GIF animation is desired; data not recognized as an animated GIF is delegated to UIImage(data: Data).

import UIKit
import AnimatedGIF

let imageView: UIImageView = UIImageView()
imageView.image = .animatedImage(data: gifData)
imageView.image = .animatedImage(data: jpegData)

By default, GIF playback behavior mimics WebKit, clamping delay between frames to a minimum of 100 milliseconds. Certain GIFs may require a custom clamp value to achieve reasonable playback speed:

import UIKit
import AnimatedGIF

let imageView: UIImageView = UIImageView()
imageView.image = .animatedImage(data: data, behavior: .unclamped) // The truth
imageView.image = .animatedImage(data: data, behavior: .clamped(0.25)) // Clamp animation frames to custom minimum delay time
imageView.image = .animatedImage(data: data, behavior: .webkit) // Default: .clamped(0.1)