获得UIView关于其superview的超级视图的位置 [英] Get position of UIView in respect to its superview's superview

查看:160
本文介绍了获得UIView关于其superview的超级视图的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIView,我已经安排了UIButtons。我想找到那些UIButton的位置。

I have a UIView, in which I have arranged UIButtons. I want to find the positions of those UIButtons.

我知道 buttons.frame 会给我这些职位,但只会尊重我的职位直接的超级视图。

I am aware that buttons.frame will give me the positions, but it will give me positions only with respect to its immediate superview.

对于UIButton superview的超级视图,我们是否有办法找到这些按钮的位置?

Is there is any way we can find the positions of those buttons, withe respect to UIButtons superview's superview?

例如,假设UIView名为firstView。

For instance, suppose there is UIView named "firstView".

然后,我有另一个UIView, secondView。这个SecondView是firstView的子视图。

Then, I have another UIView, "secondView". This "SecondView" is a subview of "firstView".

然后我将UIButton作为secondView的子视图。

Then I have UIButton as a subview on the "secondView".

->UIViewController.view
--->FirstView A
------->SecondView B
------------>Button

现在,有没有办法找到那个UIButton的位置,就firstView而言?

Now, is there any way we can find the position of that UIButton, with respect to "firstView"?

推荐答案

你可以使用这个:

目标C

CGRect frame = [firstView convertRect:buttons.frame fromView:secondView];

Swift

let frame = firstView.convert(buttons.frame, from:secondView)

文档参考:


https://developer.apple.com/documentation/uikit/uiview/1622498-convert

这篇关于获得UIView关于其superview的超级视图的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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