From 2e0bbcfb89eea971784ca275c1d15efae0bc4313 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 3 Apr 2020 17:58:47 +0800 Subject: [PATCH] iOS:UIImageView resize when one dimension is just or most,anothor is fit. --- doric-iOS/Pod/Classes/Shader/DoricImageNode.m | 7 ++----- doric-iOS/Pod/Classes/Shader/DoricLayouts.m | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m index 970596b8..841103b5 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m @@ -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 () diff --git a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m index 515988f9..10d7cee3 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m +++ b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m @@ -169,10 +169,23 @@ - (void)setFrame { - (void)measureUndefinedContent:(CGSize)targetSize { CGSize measuredSize = [self.view sizeThatFits:targetSize]; if (self.widthSpec == DoricLayoutFit) { - self.measuredWidth = measuredSize.width + self.paddingLeft + self.paddingRight; + 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) { - self.measuredHeight = measuredSize.height + self.paddingTop + self.paddingBottom; + 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; + } + } }