Last active
August 29, 2015 14:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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