Merge pull request #488 from facebook/CleanupFrameSetter

Clean up logic in setFrame: for clarity and compactness
This commit is contained in:
appleguy 2015-06-19 17:36:17 -07:00
commit c271462b16

View File

@ -143,20 +143,21 @@
ASDisplayNodeAssert(CATransform3DIsIdentity(self.transform), @"Must be an identity transform");
#endif
if (_layer && ASDisplayNodeThreadIsMain()) {
CGPoint oldBoundsOrigin = _layer.bounds.origin;
_layer.bounds = CGRectMake(oldBoundsOrigin.x, oldBoundsOrigin.y, rect.size.width, rect.size.height);
BOOL useLayer = (_layer && ASDisplayNodeThreadIsMain());
CGPoint anchorPoint = _layer.anchorPoint;
_layer.position = CGPointMake(rect.origin.x + rect.size.width * anchorPoint.x,
CGPoint origin = (useLayer ? _layer.bounds.origin : self.bounds.origin);
CGPoint anchorPoint = (useLayer ? _layer.anchorPoint : self.anchorPoint);
CGRect bounds = (CGRect){ origin, rect.size };
CGPoint position = CGPointMake(rect.origin.x + rect.size.width * anchorPoint.x,
rect.origin.y + rect.size.height * anchorPoint.y);
if (useLayer) {
_layer.bounds = bounds;
_layer.position = position;
} else {
CGPoint oldBoundsOrigin = self.bounds.origin;
self.bounds = CGRectMake(oldBoundsOrigin.x, oldBoundsOrigin.y, rect.size.width, rect.size.height);
CGPoint anchorPoint = self.anchorPoint;
self.position = CGPointMake(rect.origin.x + rect.size.width * anchorPoint.x,
rect.origin.y + rect.size.height * anchorPoint.y);
self.bounds = bounds;
self.position = position;
}
}