views:

28

answers:

2

Hi

If I have a view inside another view, than its x,y values are relevant to its parent view.

I would like to know its x y position relative to the whole screen window-

that means 320 X 480 iphone screen window

The top left corner is 0,0 of course.

What is the way for getting its "True" x ,y values?

Thanks.

A: 

Pseudo code as not on my mac and can't remember the exact structure of the objects, but something along the lines of:

x = self.parentView.frame.x + self.frame.x;
y = self.parentView.frame.y + self.frame.y;

You could easily extend this to use a loop or recursion if the views are going to be more than one deep.

s1mm0t
Note that frame coordinates won't work if a transform is applied to any of the views.
Paul Lynch
+2  A: 

Use convertPoint:toView:, where the to view is the window property - although that isn't necessarily the screen, it usually will be.

Paul Lynch