Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 2a7f45e

Browse files
committed
Merge pull request #479 from joostvandijk/rasterized-node-offset
Fix offset issue for rasterized nodes
2 parents 4ddd1f4 + bd79415 commit 2a7f45e

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

AsyncDisplayKit/Private/ASDisplayNode+AsyncDisplay.mm

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,23 @@ - (void)_recursivelyRasterizeSelfAndSublayersWithIsCancelledBlock:(asdisplaynode
8787
// Capture these outside the display block so they are retained.
8888
UIColor *backgroundColor = self.backgroundColor;
8989
CGRect bounds = self.bounds;
90-
CGPoint position = self.position;
91-
CGPoint anchorPoint = self.anchorPoint;
92-
93-
// Pretty hacky since full 3D transforms aren't actually supported, but attempt to compute the transformed frame of this node so that we can composite it into approximately the right spot.
94-
CGAffineTransform transform = CATransform3DGetAffineTransform(self.transform);
95-
CGSize scaledBoundsSize = CGSizeApplyAffineTransform(bounds.size, transform);
96-
CGPoint origin = CGPointMake(position.x - scaledBoundsSize.width * anchorPoint.x,
97-
position.y - scaledBoundsSize.height * anchorPoint.y);
98-
CGRect frame = CGRectMake(origin.x, origin.y, bounds.size.width, bounds.size.height);
90+
91+
CGRect frame;
92+
93+
// If this is the root container node, use a frame with a zero origin to draw into. If not, calculate the correct frame using the node's position, transform and anchorPoint.
94+
if (self.shouldRasterizeDescendants) {
95+
frame = CGRectMake(0.0f, 0.0f, bounds.size.width, bounds.size.height);
96+
} else {
97+
CGPoint position = self.position;
98+
CGPoint anchorPoint = self.anchorPoint;
99+
100+
// Pretty hacky since full 3D transforms aren't actually supported, but attempt to compute the transformed frame of this node so that we can composite it into approximately the right spot.
101+
CGAffineTransform transform = CATransform3DGetAffineTransform(self.transform);
102+
CGSize scaledBoundsSize = CGSizeApplyAffineTransform(bounds.size, transform);
103+
CGPoint origin = CGPointMake(position.x - scaledBoundsSize.width * anchorPoint.x,
104+
position.y - scaledBoundsSize.height * anchorPoint.y);
105+
frame = CGRectMake(origin.x, origin.y, bounds.size.width, bounds.size.height);
106+
}
99107

100108
// Get the display block for this node.
101109
asyncdisplaykit_async_transaction_operation_block_t displayBlock = [self _displayBlockWithAsynchronous:NO isCancelledBlock:isCancelledBlock rasterizing:YES];

0 commit comments

Comments
 (0)