Tusker/Tusker/Views/GIFImageView.swift

35 lines
824 B
Swift

//
// GIFImageView.swift
// Tusker
//
// Created by Shadowfacts on 11/11/21.
// Copyright © 2021 Shadowfacts. All rights reserved.
//
import UIKit
class GIFImageView: UIImageView {
private(set) var isAnimatingGIF: Bool = false
private var shouldStopAnimatingGIF = false
func animate(withGIFData data: Data) {
CGAnimateImageDataWithBlock(data as CFData, nil) { [weak self] (frameIndex, frame, stop) in
guard let self = self else {
stop.pointee = true
return
}
self.image = UIImage(cgImage: frame)
stop.pointee = self.shouldStopAnimatingGIF
}
isAnimatingGIF = true
}
func stopAnimatingGIF() {
shouldStopAnimatingGIF = true
isAnimatingGIF = false
}
}