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.
|
||||
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.
|
||||
public var isAnimatingGIF: Bool {
|
||||
return !displayLink.paused
|
||||
|
@ -35,6 +38,7 @@ public class AnimatableImageView: UIImageView {
|
|||
public func prepareForAnimation(imageData data: NSData) {
|
||||
image = UIImage(data: data)
|
||||
animator = Animator(data: data, size: frame.size, contentMode: contentMode, framePreloadCount: framePreloadCount)
|
||||
animator?.needsPrescaling = needsPrescaling
|
||||
animator?.prepareFrames()
|
||||
attachDisplayLink()
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@ class Animator {
|
|||
var currentPreloadIndex = 0
|
||||
/// Time elapsed since the last frame change. Used to determine when the frame should be updated.
|
||||
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.
|
||||
var currentFrame: UIImage? {
|
||||
|
@ -69,10 +72,14 @@ class Animator {
|
|||
let image = UIImage(CGImage: frameImageRef)
|
||||
let scaledImage: UIImage?
|
||||
|
||||
switch contentMode {
|
||||
case .ScaleAspectFit: scaledImage = image.resizeAspectFit(size)
|
||||
case .ScaleAspectFill: scaledImage = image.resizeAspectFill(size)
|
||||
default: scaledImage = image.resize(size)
|
||||
if needsPrescaling == true {
|
||||
switch contentMode {
|
||||
case .ScaleAspectFit: scaledImage = image.resizeAspectFit(size)
|
||||
case .ScaleAspectFill: scaledImage = image.resizeAspectFill(size)
|
||||
default: scaledImage = image.resize(size)
|
||||
}
|
||||
} else {
|
||||
scaledImage = image
|
||||
}
|
||||
|
||||
return AnimatedFrame(image: scaledImage, duration: frameDuration)
|
||||
|
|
Loading…
Reference in New Issue