我有很多问题:
- 如何定位 UIView,使其位于我要添加到的 View 的底部?
- 如何将 subview 添加到 View 中,以便它位于 super View 的角落,并留有一个小间隙(就像我想要一个“x”十字符号来关闭某些东西)
- 它们是一个用于轻松 UIView 定位(和旋转)的实用程序类吗?
任何引用资料、开源教程等都将受到欢迎!
最佳答案
(a) 如何定位 UIView,使其位于我要添加到的 View 的底部?
好吧,假设您要将 button
定位为 View form
底部的 subview ,您计算的 origin.y
subview 按钮
通过从表单
的高度减去按钮的高度
CGRect buttonFrame = button.frame;
buttonFrame.origin.y = form.bounds.size.height - buttonFrame.size.height;
button.frame = buttonFrame;
[form addSubview:button];
您也可以更改原点水平位置。您希望它位于表单
的左下角吗?
buttonFrame.origin.x = 0;
或者在表单的右边缘
?
buttonFrame.origin.x = form.bounds.size.width - buttonFrame.size.width;
或者在表单
的中间(水平)?
buttonFrame.origin.x = (form.bounds.size.width - buttonFrame.size.width) / 2;
或使用CGRectGetMidX
的其他方式(在 CGGeometry utility methods 中找到):
buttonFrame.origin.x = CGRectGetMidX(form.bounds) - buttonFrame.size.width/2;
当父 View 的大小发生变化时,自动调整大小可以调整框架。但你仍然需要先定位它。
关于iphone - UIView定位相关问题(iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15295573/