iPhone - 在整个UIWindow中获取UIView的位置 [英] iPhone - Get Position of UIView within entire UIWindow

查看:593
本文介绍了iPhone - 在整个UIWindow中获取UIView的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIView 的位置显然可以由 view.center 查看.frame 等,但这只返回 UIView 相对于它的即时superview的位置。



我需要确定整个320x480坐标系统中 UIView 的位置。例如,如果 UIView UITableViewCell 中,它在窗口中的位置可能会显着变化,无论超级视图。 / p>

任何想法如果以及如何可能?



干杯:)


<这是一个很容易的:

  [aView convertPoint:localPosition toView:nil]; 

...将局部坐标空间中的点转换为窗口坐标。你可以使用这个方法在窗口空间中计算视图的原点,如下所示:

  [aView.superview convertPoint:aView.frame。 origin toView:nil]; 

2014年编辑:看看Matt__C的评论,指出坐标...


  1. 在旋转设备时不会更改。


  2. 都是窗口坐标:坐标系统由窗口的边界定义。屏幕和设备坐标系统不同,不应与窗口坐标混合。


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.

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?

Cheers :)

解决方案

That's an easy one:

[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 Edit: Looking at the popularity of Matt__C's comment it seems reasonable to point out that the coordinates...

  1. don't change when rotating the device.
  2. always have their origin in the top left corner of the unrotated screen.
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆