Extends UIImage
to support GIF animation
Targets iOS/iPadOS/tvOS 14. Written in Swift 5.3 and requires Xcode 12 or newer to build.
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)