我正在努力实现以下目标:
- 我的 xib 中有 2 个视图需要保持 20 像素的边缘(两侧和顶部)
- 需要调整大小的 2 个视图大小不同
- 它们必须相距 20 像素
- 它们的宽度需要保持相对于父视图的宽度
我阅读了一个关于这样做的教程并且它有效,但它的问题是它要求两个视图具有相同的宽度和 pin Widths equally
,这是我不想要的。
这是我尝试过的:
- 向左视图添加前导空间约束为 20 像素
- 向左视图添加顶部空间约束为 20 像素
- 将顶部空间约束添加到右视图为 20 像素
- 为右视图添加拖尾空间约束为 20 像素
- 向两个视图添加水平间距约束为 20 像素
我遇到的问题是左视图没有调整大小,而右视图填充了空间以保持 20 像素的水平空间。
有没有办法让两个视图按比例调整它们应该填充的空间?
这是我的布局和约束的屏幕截图:
谢谢!
编辑
尝试旋转设备时收到以下警告:
2012-10-11 08:59:00.435 AutolayoutTest[35672:c07] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this: (1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it. (Note:
If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x8a6b2b0 H:[UIView:0x8a6b1d0(170)]>",
"<NSLayoutConstraint:0x8a68ad0 H:[UIView:0x8a69430(90)]>",
"<NSLayoutConstraint:0x8a6ba40 H:[UIView:0x8a69430]-(20)-[UIView:0x8a6b1d0]>",
"<NSLayoutConstraint:0x8a6ba00 H:[UIView:0x8a6b1d0]-(20)-| (Names: '|':UIView:0x8a6b7e0 )>",
"<NSLayoutConstraint:0x8a6b940 H:|-(20)-[UIView:0x8a69430] (Names: '|':UIView:0x8a6b7e0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7199aa0 h=--& v=--& V:[UIView:0x8a6b7e0(568)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x8a6b2b0 H:[UIView:0x8a6b1d0(170)]>