feat:fix padding compute

This commit is contained in:
pengfei.zhou 2019-12-10 14:15:32 +08:00
parent 6aa3c4bb83
commit 3d403d5178

View File

@ -251,7 +251,7 @@ - (void)layoutSelf:(CGSize)targetSize {
} else if ((gravity & RIGHT) == RIGHT) { } else if ((gravity & RIGHT) == RIGHT) {
child.right = targetSize.width - padding.right; child.right = targetSize.width - padding.right;
} else if ((gravity & CENTER_X) == CENTER_X) { } else if ((gravity & CENTER_X) == CENTER_X) {
child.centerX = (targetSize.width - padding.left - padding.right) / 2; child.centerX = targetSize.width / 2;
} else { } else {
if (childConfig.margin.left) { if (childConfig.margin.left) {
child.left = childConfig.margin.left + padding.left; child.left = childConfig.margin.left + padding.left;
@ -264,7 +264,7 @@ - (void)layoutSelf:(CGSize)targetSize {
} else if ((gravity & BOTTOM) == BOTTOM) { } else if ((gravity & BOTTOM) == BOTTOM) {
child.bottom = targetSize.height - padding.bottom; child.bottom = targetSize.height - padding.bottom;
} else if ((gravity & CENTER_Y) == CENTER_Y) { } else if ((gravity & CENTER_Y) == CENTER_Y) {
child.centerY = (targetSize.height - padding.top - padding.bottom) / 2; child.centerY = targetSize.height / 2;
} else { } else {
if (childConfig.margin.top) { if (childConfig.margin.top) {
child.top = childConfig.margin.top + padding.top; child.top = childConfig.margin.top + padding.top;
@ -323,7 +323,7 @@ - (void)layoutSelf:(CGSize)targetSize {
} else if ((self.gravity & BOTTOM) == BOTTOM) { } else if ((self.gravity & BOTTOM) == BOTTOM) {
yStart = targetSize.height - self.contentHeight - padding.bottom; yStart = targetSize.height - self.contentHeight - padding.bottom;
} else if ((self.gravity & CENTER_Y) == CENTER_Y) { } else if ((self.gravity & CENTER_Y) == CENTER_Y) {
yStart = (targetSize.height - self.contentHeight - padding.top - padding.bottom) / 2; yStart = (targetSize.height - self.contentHeight - padding.top - padding.bottom) / 2 + padding.top;
} }
CGFloat remain = targetSize.height - self.contentHeight - padding.top - padding.bottom; CGFloat remain = targetSize.height - self.contentHeight - padding.top - padding.bottom;
for (UIView *child in self.subviews) { for (UIView *child in self.subviews) {
@ -351,7 +351,7 @@ - (void)layoutSelf:(CGSize)targetSize {
} else if ((gravity & RIGHT) == RIGHT) { } else if ((gravity & RIGHT) == RIGHT) {
child.right = self.width - padding.right; child.right = self.width - padding.right;
} else if ((gravity & CENTER_X) == CENTER_X) { } else if ((gravity & CENTER_X) == CENTER_X) {
child.centerX = (targetSize.width - padding.left - padding.right) / 2; child.centerX = targetSize.width / 2;
} else if (childConfig.margin.left) { } else if (childConfig.margin.left) {
child.left = childConfig.margin.left + padding.left; child.left = childConfig.margin.left + padding.left;
} else if (childConfig.margin.right) { } else if (childConfig.margin.right) {
@ -414,7 +414,7 @@ - (void)layoutSelf:(CGSize)targetSize {
} else if ((self.gravity & RIGHT) == RIGHT) { } else if ((self.gravity & RIGHT) == RIGHT) {
xStart = targetSize.width - self.contentWidth - padding.right; xStart = targetSize.width - self.contentWidth - padding.right;
} else if ((self.gravity & CENTER_X) == CENTER_X) { } else if ((self.gravity & CENTER_X) == CENTER_X) {
xStart = (targetSize.width - self.contentWidth - padding.left - padding.right) / 2; xStart = (targetSize.width - self.contentWidth - padding.left - padding.right) / 2 + padding.left;
} }
CGFloat remain = targetSize.width - self.contentWidth - padding.left - padding.right; CGFloat remain = targetSize.width - self.contentWidth - padding.left - padding.right;
for (UIView *child in self.subviews) { for (UIView *child in self.subviews) {
@ -444,7 +444,7 @@ - (void)layoutSelf:(CGSize)targetSize {
} else if ((gravity & BOTTOM) == BOTTOM) { } else if ((gravity & BOTTOM) == BOTTOM) {
child.bottom = targetSize.height - padding.bottom; child.bottom = targetSize.height - padding.bottom;
} else if ((gravity & CENTER_Y) == CENTER_Y) { } else if ((gravity & CENTER_Y) == CENTER_Y) {
child.centerY = (targetSize.height - padding.top - padding.bottom) / 2; child.centerY = targetSize.height / 2;
} else if (childConfig.margin.top) { } else if (childConfig.margin.top) {
child.top = childConfig.margin.top + padding.top; child.top = childConfig.margin.top + padding.top;
} else if (childConfig.margin.bottom) { } else if (childConfig.margin.bottom) {