iOS: DoricLayout UIImageView support fit width or height when another dimension is certained

This commit is contained in:
pengfei.zhou 2022-08-24 20:11:20 +08:00 committed by osborn
parent 16cc6446e9
commit 6a4c69340e

View File

@ -1043,11 +1043,45 @@ - (void)undefinedMeasureWidth:(DoricMeasureSpec)widthMeasureSpec
heightMeasureSpec.size - self.paddingTop - self.paddingBottom); heightMeasureSpec.size - self.paddingTop - self.paddingBottom);
//TODO should check this //TODO should check this
CGSize measuredSize = [self.view sizeThatFits:targetSize]; CGSize measuredSize = [self.view sizeThatFits:targetSize];
DoricSizeAndState widthSizeAndState = [self resolveSizeAndState:measuredSize.width
CGFloat contentWidth = measuredSize.width;
CGFloat contentHeight = measuredSize.height;
if ([self.view isKindOfClass:UIImageView.class]) {
if (self.widthSpec == DoricLayoutFit
&& self.heightSpec != DoricLayoutFit && measuredSize.height > 0) {
DoricSizeAndState preHeightSizeAndState = [self resolveSizeAndState:contentHeight
+ self.paddingTop + self.paddingBottom
spec:heightMeasureSpec
childMeasuredState:0];
contentWidth = measuredSize.width / measuredSize.height
* (preHeightSizeAndState.size - self.paddingBottom - self.paddingBottom);
self.measuredWidth = contentWidth + self.paddingLeft + self.paddingBottom;
self.measuredHeight = preHeightSizeAndState.size;
self.measuredState = 0;
return;
}
if (self.heightSpec == DoricLayoutFit
&& self.widthSpec != DoricLayoutFit && measuredSize.width > 0) {
DoricSizeAndState preWidthSizeAndState = [self resolveSizeAndState:contentWidth
+ self.paddingLeft + self.paddingRight + self.paddingLeft + self.paddingRight
spec:widthMeasureSpec spec:widthMeasureSpec
childMeasuredState:0]; childMeasuredState:0];
DoricSizeAndState heightSizeAndState = [self resolveSizeAndState:measuredSize.height contentHeight = measuredSize.height / measuredSize.width
* (preWidthSizeAndState.size - self.paddingLeft - self.paddingRight);
self.measuredWidth = preWidthSizeAndState.size;
self.measuredHeight = contentHeight + self.paddingTop + self.paddingBottom;
self.measuredState = 0;
return;
}
}
DoricSizeAndState widthSizeAndState = [self resolveSizeAndState:contentWidth
+ self.paddingLeft + self.paddingRight
spec:widthMeasureSpec
childMeasuredState:0];
DoricSizeAndState heightSizeAndState = [self resolveSizeAndState:contentHeight
+ self.paddingTop + self.paddingBottom + self.paddingTop + self.paddingBottom
spec:heightMeasureSpec spec:heightMeasureSpec
childMeasuredState:0]; childMeasuredState:0];