Gifu/Source/Classes/AnimatedFrame.swift

31 lines
966 B
Swift
Raw Normal View History

2018-02-17 15:14:53 +00:00
import UIKit
/// Represents a single frame in a GIF.
struct AnimatedFrame {
/// The image to display for this frame. Its value is nil when the frame is removed from the buffer.
let image: UIImage?
/// The duration that this frame should remain active.
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 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.
/// - returns: An `AnimatedFrame` instance.
2016-10-01 11:41:22 +00:00
func makeAnimatedFrame(with newImage: UIImage?) -> AnimatedFrame {
return AnimatedFrame(image: newImage, duration: duration)
}
}