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? {
|
2014-12-12 20:29:17 +00:00
|
|
|
return image as? AnimatedImage
|
2014-09-06 14:12:09 +00:00
|
|
|
}
|
|
|
|
|
2014-11-10 21:57:37 +00:00
|
|
|
var isAnimatingGIF: Bool {
|
|
|
|
return animatableImage?.isAnimating() ?? isAnimating()
|
2014-09-06 14:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var animatable: Bool {
|
2014-12-12 20:29:17 +00:00
|
|
|
return animatableImage != .None
|
2014-09-06 14:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Method Overrides
|
|
|
|
override public func displayLayer(layer: CALayer!) {
|
2014-12-12 20:29:17 +00:00
|
|
|
layer.contents = animatableImage?.currentFrame?.CGImage
|
2014-09-06 14:12:09 +00:00
|
|
|
}
|
|
|
|
|
2014-09-10 19:12:54 +00:00
|
|
|
// MARK: - Setter Methods
|
2014-12-12 20:29:17 +00:00
|
|
|
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
|
2014-11-10 21:57:37 +00:00
|
|
|
func startAnimatingGIF() {
|
2014-12-12 20:29:17 +00:00
|
|
|
animatableImage?.resumeAnimation() ?? startAnimating()
|
2014-09-06 14:12:09 +00:00
|
|
|
}
|
|
|
|
|
2014-11-10 21:57:37 +00:00
|
|
|
func stopAnimatingGIF() {
|
2014-12-12 20:29:17 +00:00
|
|
|
animatableImage?.pauseAnimation() ?? stopAnimating()
|
2014-09-06 14:12:09 +00:00
|
|
|
}
|
|
|
|
}
|