views:

136

answers:

2

Example: I have a CGPoint in window coordinates:

CGPoint windowPoint = CGPointMake(220.0f, 400.0f);

There is aView which has a superview in a superview in a superview. Somewhere deep in the view hierarchy, probably even transformed a few times.

When you get a UITouch, you can ask it for -locationInView: and it will return the coordinates relative to that view.

I need pretty much the same thing. Is there an easy way to accomplish that?

A: 

Perhaps you could iterate through the superview tree, drilling down to subviews by tag, and add or subtract the subview's frame.origin values to get to a translated windowPoint relative to the view-of-interest's frame.origin.

Alex Reynolds
+1  A: 

I found an really easy solution:

[self.aView convertPoint:windowPoint fromView:self.window];
dontWatchMyProfile
There are several conversion routines like that one provided by UIView. They're all described in the UIView class reference guide. http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/convertPoint:fromView:
progrmr