您好我设计了一个使用AutoLayout constriants的XIB来显示两行按钮,每行有三个按钮,如屏幕截图所示(在获得满意的布局后,我会将按钮放在Red UIViews中):
到目前为止一直很好,在如上图所示的纵向模式下按钮看起来很好。然而,当我旋转到横向时,标题(蓝色)和父视图(灰色)调整大小并正确显示,但红色按钮视图刚刚消失(见下文)。
设置约束以使其正常工作的最佳方法是什么?我已经按照Ray Wenderlich教程使用了他在他的示例中使用的相同Editor \ Pin] Vertical Spacing和Editor \ Pin \ Horizontal间距: Ray Wenderlich tutorial
我也遇到了很多约束错误,如下所示:
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:0x859abe0 UIView:0x85a8fb0.height == UIView:0x85a8e60.height>",
"<NSLayoutConstraint:0x859ab60 V:[UIView:0x85a8fb0]-(114)-| (Names: '|':UIView:0x85a8170 )>",
"<NSLayoutConstraint:0x859ab20 V:|-(424)-[UIView:0x85a8fb0] (Names: '|':UIView:0x85a8170 )>",
"<NSLayoutConstraint:0x85a3430 V:|-(150)-[UIView:0x85a8170] (Names: '|':UIView:0x85a8da0 )>",
"<NSLayoutConstraint:0x85a33b0 V:[UIView:0x85a8170]-(NSSpace(20))-| (Names: '|':UIView:0x85a8da0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x75ac610 h=--& v=--& V:[UIView:0x85a8da0(704)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x859ab60 V:[UIView:0x85a8fb0]-(114)-| (Names: '|':UIView:0x85a8170 )>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
我的斗智尽头,所以这个博学群体的任何帮助都会非常感激......!
答案 0 :(得分:2)
错误意味着您有相互冲突的约束。试着让它在一行工作。