开发者

How to find out the "True" x ,y values of a view

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.

开发者_JAVA技巧What is the way for getting its "True" x ,y values?

Thanks.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜