Gifu/Source/UIImageView+Gifu.swift

38 lines
839 B
Swift
Raw Normal View History

2014-09-06 14:12:09 +00:00
import UIKit
2014-12-08 22:11:24 +00:00
public extension UIImageView {
2014-09-06 14:12:09 +00:00
// MARK: - Computed Properties
var animatableImage: AnimatedImage? {
return image as? AnimatedImage
2014-09-06 14:12:09 +00:00
}
var isAnimatingGIF: Bool {
return animatableImage?.isAnimating() ?? isAnimating()
2014-09-06 14:12:09 +00:00
}
var animatable: Bool {
return animatableImage != .None
2014-09-06 14:12:09 +00:00
}
// MARK: - Method Overrides
override public func displayLayer(layer: CALayer!) {
layer.contents = animatableImage?.currentFrame?.CGImage
2014-09-06 14:12:09 +00:00
}
2014-09-10 19:12:54 +00:00
// MARK: - Setter Methods
public func setAnimatedImage(image: AnimatedImage) {
image.delegate = self
self.image = image
2014-09-11 21:06:16 +00:00
layer.setNeedsDisplay()
2014-09-06 14:12:09 +00:00
}
// MARK: - Animation
func startAnimatingGIF() {
animatableImage?.resumeAnimation() ?? startAnimating()
2014-09-06 14:12:09 +00:00
}
func stopAnimatingGIF() {
animatableImage?.pauseAnimation() ?? stopAnimating()
2014-09-06 14:12:09 +00:00
}
}