From cf7a5a626bb673b5f4fa4673870f3b531badf121 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 30 Mar 2019 15:47:41 +0800 Subject: [PATCH] Remove the unused intrinsicContentSize for SDAnimatedImageView. This is original from FL and it's proved to be a of FL itself, but not what UIKit/AppKit behavior. --- SDWebImage/SDAnimatedImageView.m | 19 ------------------- Tests/Tests/SDAnimatedImageTest.m | 8 ++++++++ 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/SDWebImage/SDAnimatedImageView.m b/SDWebImage/SDAnimatedImageView.m index fc4a9988..b64e746c 100644 --- a/SDWebImage/SDAnimatedImageView.m +++ b/SDWebImage/SDAnimatedImageView.m @@ -228,8 +228,6 @@ static NSUInteger SDDeviceFreeMemory() { // Ensure disabled highlighting; it's not supported (see `-setHighlighted:`). super.highlighted = NO; - // UIImageView seems to bypass some accessors when calculating its intrinsic content size, so this ensures its intrinsic content size comes from the animated image. - [self invalidateIntrinsicContentSize]; // Calculate max buffer size [self calculateMaxBufferCount]; @@ -429,23 +427,6 @@ static NSUInteger SDDeviceFreeMemory() { } } -#pragma mark Auto Layout - -- (CGSize)intrinsicContentSize -{ - // Default to let UIImageView handle the sizing of its image, and anything else it might consider. - CGSize intrinsicContentSize = [super intrinsicContentSize]; - - // If we have have an animated image, use its image size. - // UIImageView's intrinsic content size seems to be the size of its image. The obvious approach, simply calling `-invalidateIntrinsicContentSize` when setting an animated image, results in UIImageView steadfastly returning `{UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric}` for its intrinsicContentSize. - // (Perhaps UIImageView bypasses its `-image` getter in its implementation of `-intrinsicContentSize`, as `-image` is not called after calling `-invalidateIntrinsicContentSize`.) - if (self.animatedImage) { - intrinsicContentSize = self.image.size; - } - - return intrinsicContentSize; -} - #pragma mark - UIImageView Method Overrides #pragma mark Image Data diff --git a/Tests/Tests/SDAnimatedImageTest.m b/Tests/Tests/SDAnimatedImageTest.m index 5af4b002..0135b4e4 100644 --- a/Tests/Tests/SDAnimatedImageTest.m +++ b/Tests/Tests/SDAnimatedImageTest.m @@ -129,6 +129,14 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun expect(image1.animatedImageFrameCount).equal(image2.animatedImageFrameCount); } +- (void)test11AnimatedImageViewIntrinsicContentSize { + // Test that SDAnimatedImageView.intrinsicContentSize return the correct value of image size + SDAnimatedImageView *imageView = [SDAnimatedImageView new]; + SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testAPNGPData]]; + imageView.image = image; + expect(imageView.intrinsicContentSize).equal(image.size); +} + - (void)test20AnimatedImageViewRendering { XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView rendering"]; SDAnimatedImageView *imageView = [[SDAnimatedImageView alloc] init];