Add needsPrescaling public property
- This exposes the ability to turn off frame prescaling. - Closes #40
This commit is contained in:
parent
0b77356888
commit
ad67756cef
|
@ -10,6 +10,9 @@ public class AnimatableImageView: UIImageView {
|
||||||
/// The size of the frame cache.
|
/// The size of the frame cache.
|
||||||
public var framePreloadCount = 50
|
public var framePreloadCount = 50
|
||||||
|
|
||||||
|
/// Specifies whether the GIF frames should be pre-scaled to save memory. Default is **true**.
|
||||||
|
public var needsPrescaling = true
|
||||||
|
|
||||||
/// A computed property that returns whether the image view is animating.
|
/// A computed property that returns whether the image view is animating.
|
||||||
public var isAnimatingGIF: Bool {
|
public var isAnimatingGIF: Bool {
|
||||||
return !displayLink.paused
|
return !displayLink.paused
|
||||||
|
@ -35,6 +38,7 @@ public class AnimatableImageView: UIImageView {
|
||||||
public func prepareForAnimation(imageData data: NSData) {
|
public func prepareForAnimation(imageData data: NSData) {
|
||||||
image = UIImage(data: data)
|
image = UIImage(data: data)
|
||||||
animator = Animator(data: data, size: frame.size, contentMode: contentMode, framePreloadCount: framePreloadCount)
|
animator = Animator(data: data, size: frame.size, contentMode: contentMode, framePreloadCount: framePreloadCount)
|
||||||
|
animator?.needsPrescaling = needsPrescaling
|
||||||
animator?.prepareFrames()
|
animator?.prepareFrames()
|
||||||
attachDisplayLink()
|
attachDisplayLink()
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,9 @@ class Animator {
|
||||||
var currentPreloadIndex = 0
|
var currentPreloadIndex = 0
|
||||||
/// Time elapsed since the last frame change. Used to determine when the frame should be updated.
|
/// Time elapsed since the last frame change. Used to determine when the frame should be updated.
|
||||||
var timeSinceLastFrameChange: NSTimeInterval = 0.0
|
var timeSinceLastFrameChange: NSTimeInterval = 0.0
|
||||||
|
/// Specifies whether GIF frames should be pre-scaled.
|
||||||
|
/// - seealso: `needsPrescaling` in AnimatableImageView.
|
||||||
|
var needsPrescaling = true
|
||||||
|
|
||||||
/// The current image frame to show.
|
/// The current image frame to show.
|
||||||
var currentFrame: UIImage? {
|
var currentFrame: UIImage? {
|
||||||
|
@ -69,11 +72,15 @@ class Animator {
|
||||||
let image = UIImage(CGImage: frameImageRef)
|
let image = UIImage(CGImage: frameImageRef)
|
||||||
let scaledImage: UIImage?
|
let scaledImage: UIImage?
|
||||||
|
|
||||||
|
if needsPrescaling == true {
|
||||||
switch contentMode {
|
switch contentMode {
|
||||||
case .ScaleAspectFit: scaledImage = image.resizeAspectFit(size)
|
case .ScaleAspectFit: scaledImage = image.resizeAspectFit(size)
|
||||||
case .ScaleAspectFill: scaledImage = image.resizeAspectFill(size)
|
case .ScaleAspectFill: scaledImage = image.resizeAspectFill(size)
|
||||||
default: scaledImage = image.resize(size)
|
default: scaledImage = image.resize(size)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
scaledImage = image
|
||||||
|
}
|
||||||
|
|
||||||
return AnimatedFrame(image: scaledImage, duration: frameDuration)
|
return AnimatedFrame(image: scaledImage, duration: frameDuration)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue