diff --git a/Source/AnimatableImageView.swift b/Source/AnimatableImageView.swift index 500a8ac..7a63bd1 100644 --- a/Source/AnimatableImageView.swift +++ b/Source/AnimatableImageView.swift @@ -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() } diff --git a/Source/Animator.swift b/Source/Animator.swift index 86398cd..f10cff6 100644 --- a/Source/Animator.swift +++ b/Source/Animator.swift @@ -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)