Skip to content

Instantly share code, notes, and snippets.

@cbowns cbowns/gist:2992390
Created Jun 26, 2012

Embed
What would you like to do?
Helper function for moving UIView/CALayer centers when changing anchorPoints
- (CGPoint)center:(CGPoint)oldCenter movedFromAnchorPoint:(CGPoint)oldAnchorPoint toAnchorPoint:(CGPoint)newAnchorPoint withFrame:(CGRect)frame;
{
CGPoint anchorPointDiff = CGPointMake(newAnchorPoint.x - oldAnchorPoint.x, newAnchorPoint.y - oldAnchorPoint.y);
CGPoint newCenter = CGPointMake(oldCenter.x + (anchorPointDiff.x * frame.size.width),
oldCenter.y + (anchorPointDiff.y * frame.size.height));
return newCenter;
}
@cbowns

This comment has been minimized.

Copy link
Owner Author

commented Jul 12, 2012

Example usage:

CGPoint newTopViewAnchorPoint = CGPointMake(0.5, 1.0);
CGPoint newTopViewCenter = [self center:topHalfFrontView.center movedFromAnchorPoint:topHalfFrontView.layer.anchorPoint toAnchorPoint:newTopViewAnchorPoint withFrame:topHalfFrontView.frame];
topHalfFrontView.layer.anchorPoint = newTopViewAnchorPoint;
topHalfFrontView.center = newTopViewCenter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.