Created
June 17, 2010 16:32
-
-
Save samsonjs/442357 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@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