iPhone - 在整个 UIWindow 中获取 UIView 的位置 [英] iPhone - Get Position of UIView within entire UIWindow
问题描述
UIView
的位置显然可以由 view.center
或 view.frame
等来确定,但这只会返回UIView
与它的直接超级视图相关.
The position of a UIView
can obviously be determined by view.center
or view.frame
etc. but this only returns the position of the UIView
in relation to it's immediate superview.
我需要确定 UIView
在整个 320x480 坐标系中的位置.例如,如果 UIView
位于 UITableViewCell
中,它在窗口中的位置可能会发生巨大变化,而不管超级视图如何.
I need to determine the position of the UIView
in the entire 320x480 co-ordinate system. For example, if the UIView
is in a UITableViewCell
it's position within the window could change dramatically irregardless of the superview.
任何想法是否可行以及如何实现?
Any ideas if and how this is possible?
干杯:)
推荐答案
这很简单:
[aView convertPoint:localPosition toView:nil];
... 将局部坐标空间中的一个点转换为窗口坐标.您可以使用此方法在窗口空间中计算视图的原点,如下所示:
... converts a point in local coordinate space to window coordinates. You can use this method to calculate a view's origin in window space like this:
[aView.superview convertPoint:aView.frame.origin toView:nil];
2014 年 看看 Matt__C 评论的流行程度,指出坐标...
2014 Looking at the popularity of Matt__C's comment it seems reasonable to point out that the coordinates...
- 旋转设备时不要改变.
- 原点始终位于未旋转屏幕的左上角.
- are 窗口坐标:坐标系由窗口的边界定义.屏幕和设备坐标系不同,不应与窗口坐标混淆.
- don't change when rotating the device.
- always have their origin in the top left corner of the unrotated screen.
- are window coordinates: The coordinate system ist defined by the bounds of the window. The screen's and device coordinate systems are different and should not be mixed up with window coordinates.
这篇关于iPhone - 在整个 UIWindow 中获取 UIView 的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!