2015-01-23 00:02:08 +00:00
|
|
|
/// Keeps a reference to an `UIImage` instance and its duration as a GIF frame.
|
2014-12-12 20:29:17 +00:00
|
|
|
struct AnimatedFrame {
|
2016-04-24 09:28:09 +00:00
|
|
|
/// The image that should be used for this frame.
|
2014-12-12 20:29:17 +00:00
|
|
|
let image: UIImage?
|
2016-04-24 09:28:09 +00:00
|
|
|
/// The duration that the frame image should be displayed.
|
2016-06-18 22:56:52 +00:00
|
|
|
let duration: TimeInterval
|
2015-06-09 21:28:11 +00:00
|
|
|
|
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 {
|
2016-06-18 22:56:52 +00:00
|
|
|
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.
|
2016-06-18 22:56:52 +00:00
|
|
|
func animatedFrame(with newImage: UIImage?) -> AnimatedFrame {
|
|
|
|
return AnimatedFrame(image: newImage, duration: duration)
|
2015-06-09 21:28:11 +00:00
|
|
|
}
|
2014-12-12 20:29:17 +00:00
|
|
|
}
|
2015-06-09 21:28:11 +00:00
|
|
|
|