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.

This commit is contained in:
DreamPiggy 2019-03-30 15:47:41 +08:00
parent 4235e3e302
commit cf7a5a626b
2 changed files with 8 additions and 19 deletions

View File

@ -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

View File

@ -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];