28 lines
987 B
Swift
28 lines
987 B
Swift
/// Keeps a reference to an `UIImage` instance and its duration as a GIF frame.
|
|
struct AnimatedFrame {
|
|
/// The image that should be used for this frame.
|
|
let image: UIImage?
|
|
/// The duration that the frame image should be displayed.
|
|
let duration: TimeInterval
|
|
|
|
/// A placeholder frame with no image assigned.
|
|
/// Used to replace frames that are no longer needed in the animation.
|
|
var placeholderFrame: AnimatedFrame {
|
|
return AnimatedFrame(image: nil, duration: duration)
|
|
}
|
|
|
|
/// Whether the AnimatedFrame instance contains an image or not.
|
|
var isPlaceholder: Bool {
|
|
return image == .none
|
|
}
|
|
|
|
/// Takes an optional image and returns an non-placeholder `AnimatedFrame`.
|
|
///
|
|
/// - parameter image: An optional `UIImage` instance to be assigned to the new frame.
|
|
/// - returns: A non-placeholder `AnimatedFrame` instance.
|
|
func animatedFrame(with newImage: UIImage?) -> AnimatedFrame {
|
|
return AnimatedFrame(image: newImage, duration: duration)
|
|
}
|
|
}
|
|
|