如何在自动布局视图中获取 UIButton 位置
How to get UIButton position in an auto layout View
我在 UIView's
控制器上有一个 UIButton
。 UIButton
的位置距 UIView 顶部 10 像素,距另一个 UILabel 10 像素,而另一个 UILabel 距 UIView 尾部位置 20 像素。 UIButton
和 UILabel
都具有相同的高度和宽度。该视图是在自动布局模式下设计的。
按钮和标签在UIView's
控制器中的位置
UIView
-> `UIButton`, `UILabel`
------------------------------
| | |
| 10 |
| | |
| B - 20 - L |
| |
------------------------------
在 ViewDidLoad
方法中检索到的 UIButton 的位置不正确,因为它反映了 xib 的初始位置,但加载视图后,按钮位置将随着使用自动布局而改变。
请告诉我如何在显示 UIView
后检索 UIButton
位置 (x & y)。
viewdidload
方法如下,
- (void) Viewdidload() {
[UIView addSubview:object1];
---
[UIView addSubview:object2];
}
谢谢。
视图在生命周期 viewDidLoad()
被调用时不会(自动)布局。
获取viewDidAppear()
或viewWillAppear()
中的位置。
我在 UIView's
控制器上有一个 UIButton
。 UIButton
的位置距 UIView 顶部 10 像素,距另一个 UILabel 10 像素,而另一个 UILabel 距 UIView 尾部位置 20 像素。 UIButton
和 UILabel
都具有相同的高度和宽度。该视图是在自动布局模式下设计的。
按钮和标签在UIView's
控制器中的位置
UIView
-> `UIButton`, `UILabel`
------------------------------
| | |
| 10 |
| | |
| B - 20 - L |
| |
------------------------------
在 ViewDidLoad
方法中检索到的 UIButton 的位置不正确,因为它反映了 xib 的初始位置,但加载视图后,按钮位置将随着使用自动布局而改变。
请告诉我如何在显示 UIView
后检索 UIButton
位置 (x & y)。
viewdidload
方法如下,
- (void) Viewdidload() {
[UIView addSubview:object1];
---
[UIView addSubview:object2];
}
谢谢。
视图在生命周期 viewDidLoad()
被调用时不会(自动)布局。
获取viewDidAppear()
或viewWillAppear()
中的位置。