我有一个UIView,其中安排了UIButtons。我想找到那些UIButton的位置。
我知道buttons.frame
会给我职位,但仅就其直接监督而言,我会给我职位。
关于UIButtons super View 的 super View ,有什么方法可以找到这些按钮的位置?
例如,假设有一个名为“firstView”的UIView。
然后,我有另一个UIView,“secondView”。该“SecondView”是“firstView”的 subview 。
然后,我将UIButton作为“secondView”的 subview 。
->UIViewController.view
--->FirstView A
------->SecondView B
------------>Button
现在,有什么方法可以找到该UIButton相对于“firstView”的位置吗?
最佳答案
您可以使用此:
物镜
CGRect frame = [firstView convertRect:buttons.frame fromView:secondView];
迅速
let frame = firstView.convert(buttons.frame, from:secondView)
文档引用: