iOS:UIImageView resize when one dimension is just or most,anothor is fit.

This commit is contained in:
pengfei.zhou 2020-04-03 17:58:47 +08:00 committed by osborn
parent 870a7e74af
commit 2e0bbcfb89
2 changed files with 17 additions and 7 deletions

View File

@ -21,17 +21,14 @@
//
#import "DoricImageNode.h"
#import "Doric.h"
#import "YYWebImage.h"
#import "DoricExtensions.h"
#import "DoricUtil.h"
@interface DoricImageView : YYAnimatedImageView
@end
@implementation DoricImageView
- (CGSize)sizeThatFits:(CGSize)size {
return [self sizeThatFits:size];
}
@end
@interface DoricImageNode ()

View File

@ -169,11 +169,24 @@ - (void)setFrame {
- (void)measureUndefinedContent:(CGSize)targetSize {
CGSize measuredSize = [self.view sizeThatFits:targetSize];
if (self.widthSpec == DoricLayoutFit) {
if ([self.view isKindOfClass:[UIImageView class]]
&& self.heightSpec != DoricLayoutFit && measuredSize.height > 0) {
self.measuredWidth = measuredSize.width / measuredSize.height * self.measuredHeight
+ self.paddingLeft + self.paddingRight;
} else {
self.measuredWidth = measuredSize.width + self.paddingLeft + self.paddingRight;
}
}
if (self.heightSpec == DoricLayoutFit) {
if ([self.view isKindOfClass:[UIImageView class]]
&& self.widthSpec != DoricLayoutFit && measuredSize.width > 0) {
self.measuredHeight = measuredSize.height / measuredSize.width * self.measuredWidth
+ self.paddingTop + self.paddingBottom;
} else {
self.measuredHeight = measuredSize.height + self.paddingTop + self.paddingBottom;
}
}
}
- (CGFloat)takenWidth {