有没有办法以编程方式将应用程序添加到所有空间?我希望我的应用程序默认位于所有空间。
所以我有两个矩形视图和一个将它们连接在一起的视图.见图http://cl.ly/image/340Q1l381b3L
是否可以约束红色视图,使其保持在绿色视图的垂直边界内?我想把它放在重叠区域的中心位置.
虽然这不会使它保持居中,但我认为我只能将以下两个约束应用于绿色视图和红色视图,以至少保持红色视图绑定到绿色视图.
[NSLayoutConstraint
constraintWithItem:redView
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:greenView
attribute:NSLayoutAttributeBottom
multiplier:1.0f
constant:0.0f];
[NSLayoutConstraint
constraintWithItem:redView
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationLessThanOrEqual
toItem:greenView
attribute:NSLayoutAttributeTop
multiplier:1.0f
constant:0.0f];
Run Code Online (Sandbox Code Playgroud)
但这导致了
2013-06-26 22:13:27.493 MiniMeasure [25896:303]无法同时满足约束:("NSLayoutConstraint:0x1002cebf0 RedView:0x1002cdf90.centerY> = GreenView:0x1018a34c0.bottom","NSLayoutConstraint:0x1002cf720 RedView:0x1002cdf90.centerY <= GreenView:0x1018a34c0.top","NSLayoutConstraint:0x1002bb1e0 V:[GreenView:0x1018a34c0(157)]")将尝试通过破坏约束来恢复NSLayoutConstraint:0x1002bb1e0 V:[GreenView:0x1018a34c0(157)]
很明显,它不喜欢绿色视图中的一个具有高度约束并试图打破它.但我需要绿色视图来保持它们的大小.两个绿色视图都有宽度和高度限制.
有什么想法/建议?
谢谢!