Gifu/source/UIImageView+Gifu.swift

52 lines
1.0 KiB
Swift
Raw Normal View History

2014-09-06 14:12:09 +00:00
import UIKit
extension UIImageView {
// MARK: - Computed Properties
var animatableImage: AnimatedImage? {
if image is AnimatedImage {
return image as? AnimatedImage
} else {
return nil
}
}
var isAnimating: Bool {
return animatableImage?.isAnimating() ?? false
}
var animatable: Bool {
return animatableImage != nil
}
// MARK: - Method Overrides
override public func displayLayer(layer: CALayer!) {
if let image = animatableImage {
if let frame = image.currentFrame {
layer.contents = frame.CGImage
}
}
}
2014-09-10 19:12:54 +00:00
// MARK: - Setter Methods
2014-09-07 20:35:11 +00:00
func setAnimatableImage(named name: String) {
2014-09-06 14:12:09 +00:00
image = AnimatedImage.imageWithName(name, delegate: self)
}
2014-09-07 20:35:11 +00:00
func setAnimatableImage(#data: NSData) {
2014-09-06 14:12:09 +00:00
image = AnimatedImage.imageWithData(data, delegate: self)
}
// MARK: - Animation
func startAnimating() {
if animatable {
animatableImage!.startAnimating()
}
}
func stopAnimating() {
if animatable {
animatableImage!.stopAnimating()
}
}
}