Skip to content

Instantly share code, notes, and snippets.

@inorganik
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inorganik/7bcfeebbc2ccabe87b71 to your computer and use it in GitHub Desktop.
Save inorganik/7bcfeebbc2ccabe87b71 to your computer and use it in GitHub Desktop.
Changes a frame for a rect with a default anchorPoint of (.5, .5) to remain in the same place with a different anchorPoint, because you can't change an anchorPoint in interface builder
// changes frame for a rect with a default anchorPoint of (.5, .5) to remain
// in the same place with a different anchorPoint, because you can't change
// an anchorPoint in interface builder
-(CGRect) translateFrame:(CGRect)frame forAnchorPoint:(CGPoint)anchorPoint {
NSLog(@"translate frame starting frame: %@ for anchorPoint: %@", NSStringFromCGRect(frame), NSStringFromCGPoint(anchorPoint));
CGRect newFrame = frame;
float xAdjustment = anchorPoint.x - .5;
float yAdjustment = anchorPoint.y - .5;
newFrame.origin.x = frame.origin.x + frame.size.width * xAdjustment;
newFrame.origin.y = frame.origin.y + frame.size.height * yAdjustment;
NSLog(@"- returning new frame: %@ ", NSStringFromCGRect(newFrame));
return newFrame;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment