2018-02-17 15:14:53 +00:00
|
|
|
import UIKit
|
2016-09-26 21:01:27 +00:00
|
|
|
/// Represents a single frame in a GIF.
|
2014-12-12 20:29:17 +00:00
|
|
|
struct AnimatedFrame {
|
2016-09-26 21:01:27 +00:00
|
|
|
|
|
|
|
/// The image to display for this frame. Its value is nil when the frame is removed from the buffer.
|
2014-12-12 20:29:17 +00:00
|
|
|
let image: UIImage?
|
2016-09-26 21:01:27 +00:00
|
|
|
|
|
|
|
/// The duration that this frame should remain active.
|
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)
|
|
|
|
}
|
|
|
|
|
2016-09-26 21:01:27 +00:00
|
|
|
/// Whether this frame instance contains an image or not.
|
2016-04-24 09:28:09 +00:00
|
|
|
var isPlaceholder: Bool {
|
2017-07-02 22:19:42 +00:00
|
|
|
return image == nil
|
2016-04-24 09:28:09 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 21:12:14 +00:00
|
|
|
/// Returns a new instance from an optional image.
|
2016-04-24 09:28:09 +00:00
|
|
|
///
|
|
|
|
/// - parameter image: An optional `UIImage` instance to be assigned to the new frame.
|
2016-09-26 21:01:27 +00:00
|
|
|
/// - returns: An `AnimatedFrame` instance.
|
2016-10-01 11:41:22 +00:00
|
|
|
func makeAnimatedFrame(with newImage: UIImage?) -> AnimatedFrame {
|
2016-06-18 22:56:52 +00:00
|
|
|
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
|
|
|
|