Skip to content

Instantly share code, notes, and snippets.

@samsonjs
Created June 17, 2010 16:32
Show Gist options
  • Save samsonjs/442357 to your computer and use it in GitHub Desktop.
Save samsonjs/442357 to your computer and use it in GitHub Desktop.
@implementation CPView (RelativeCoordinates)
- (CGPoint) coordinatesRelativeToView: (CPView)rootView
{
var viewFrame = [self frame];
var x = viewFrame.origin.x;
var y = viewFrame.origin.y;
var curParentView = [self superview];
while (curParentView != rootView) {
var frame = [curParentView frame];
x += frame.origin.x;
y += frame.origin.y;
if ([[curParentView class] isKindOfClass: [CPScrollView class]]) {
var clipRectOrigin = [[curParentView contentView] boundsOrigin];
x -= clipRectOrigin.x;
y -= clipRectOrigin.y;
}
curParentView = [curParentView superview];
}
return CGPointMake(x, y);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment