Gifu/Source/AnimatedFrame.swift

28 lines
987 B
Swift
Raw Normal View History

2015-01-23 00:02:08 +00:00
/// Keeps a reference to an `UIImage` instance and its duration as a GIF frame.
struct AnimatedFrame {
2016-04-24 09:28:09 +00:00
/// The image that should be used for this frame.
let image: UIImage?
2016-04-24 09:28:09 +00:00
/// The duration that the frame image should be displayed.
let duration: TimeInterval
2016-04-24 09:28:09 +00:00
/// 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
2016-04-24 09:28:09 +00:00
}
/// 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)
}
}