From 7f26910f0c0059ef3750e98aa0752d908a30d374 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 8 Apr 2020 16:07:15 +0800 Subject: [PATCH] iOS:when measure child ,remove margin --- doric-iOS/Pod/Classes/Shader/DoricLayouts.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m index 5b3bb623..8e3011cf 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m +++ b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m @@ -216,6 +216,12 @@ - (CGFloat)takenHeight { return self.measuredHeight + self.marginTop + self.marginBottom; } +- (CGSize)removeMargin:(CGSize)targetSize { + return CGSizeMake( + targetSize.width - self.marginLeft - self.marginRight, + targetSize.height - self.marginTop - self.marginBottom); +} + - (void)measureStackContent:(CGSize)targetSize { CGFloat contentWidth = 0, contentHeight = 0; for (__kindof UIView *subview in self.view.subviews) { @@ -223,7 +229,7 @@ - (void)measureStackContent:(CGSize)targetSize { if (layout.disabled) { continue; } - [layout measure:targetSize]; + [layout measure:[layout removeMargin:targetSize]]; contentWidth = MAX(contentWidth, layout.takenWidth); contentHeight = MAX(contentHeight, layout.takenHeight); } @@ -249,7 +255,7 @@ - (void)measureVLayoutContent:(CGSize)targetSize { continue; } had = YES; - [layout measure:CGSizeMake(targetSize.width, targetSize.height - contentHeight)]; + [layout measure:[layout removeMargin:CGSizeMake(targetSize.width, targetSize.height - contentHeight)]]; contentWidth = MAX(contentWidth, layout.takenWidth); contentHeight += layout.takenHeight + self.spacing; contentWeight += layout.weight; @@ -299,7 +305,7 @@ - (void)measureHLayoutContent:(CGSize)targetSize { continue; } had = YES; - [layout measure:CGSizeMake(targetSize.width - contentWidth, targetSize.height)]; + [layout measure:[layout removeMargin:CGSizeMake(targetSize.width - contentWidth, targetSize.height)]]; contentWidth += layout.takenWidth + self.spacing; contentHeight = MAX(contentHeight, layout.takenHeight); contentWeight += layout.weight;