From 656a98b149c849b1e2c4ad74465a96fb6c883349 Mon Sep 17 00:00:00 2001 From: vvveiii Date: Fri, 14 Aug 2020 19:24:55 +0800 Subject: [PATCH] =?UTF-8?q?[YogaKit]=20align=20pixel=20for=20view=E2=80=99?= =?UTF-8?q?s=20size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YogaKit/Source/YGLayout.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 1cec9575..647a3a34 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -491,6 +491,11 @@ static CGFloat YGRoundPixelValue(CGFloat value) { return round(value * scale) / scale; } +static CGFloat YGAlignPixelValue(CGFloat value) { + CGFloat scale = YGScaleFactor(); + return ceil(value * scale) / scale; +} + static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) { NSCAssert( [NSThread isMainThread], @@ -555,12 +560,12 @@ static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) { view.frame = (CGRect) { .origin = CGPointMake(YGRoundPixelValue(frame.origin.x), YGRoundPixelValue(frame.origin.y)), - .size = CGSizeMake(YGRoundPixelValue(frame.size.width), YGRoundPixelValue(frame.size.height)) + .size = CGSizeMake(YGAlignPixelValue(frame.size.width), YGAlignPixelValue(frame.size.height)) }; #else view.bounds = (CGRect) { .origin = view.bounds.origin, - .size = CGSizeMake(YGRoundPixelValue(CGRectGetWidth(frame)), YGRoundPixelValue(CGRectGetHeight(frame))) + .size = CGSizeMake(YGAlignPixelValue(CGRectGetWidth(frame)), YGAlignPixelValue(CGRectGetHeight(frame))) }; view.center = (CGPoint) {