Gifu/Source/UIImageView+Gifu.swift

38 lines
839 B
Swift
Executable File

import UIKit
public extension UIImageView {
// MARK: - Computed Properties
var animatableImage: AnimatedImage? {
return image as? AnimatedImage
}
var isAnimatingGIF: Bool {
return animatableImage?.isAnimating() ?? isAnimating()
}
var animatable: Bool {
return animatableImage != .None
}
// MARK: - Method Overrides
override public func displayLayer(layer: CALayer!) {
layer.contents = animatableImage?.currentFrame?.CGImage
}
// MARK: - Setter Methods
public func setAnimatedImage(image: AnimatedImage) {
image.delegate = self
self.image = image
layer.setNeedsDisplay()
}
// MARK: - Animation
func startAnimatingGIF() {
animatableImage?.resumeAnimation() ?? startAnimating()
}
func stopAnimatingGIF() {
animatableImage?.pauseAnimation() ?? stopAnimating()
}
}