在自动布局中设置五个水平按钮时出现问题

时间:2014-12-29 08:01:00

标签: ios storyboard autolayout

我正在使用自动布局在视图底部创建五个按钮。布局如下图所示,棕色显示间隔视图,数字显示我正在使用的按钮。

当我设置约束时,我发现对于iPhone,视图没有调整大小,我们错过了按钮,如下面的屏幕截图所示。按钮被隐藏,没有调整大小。

当我在iPad上运行时,最后一个间隔视图正在调整大小,而其他

此外,日志中存在一些我无法理解的错误。

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:0x7f8673d62320 H:[UIView:0x7f8673f08c40]-(398)-|   (Names: '|':UIView:0x7f8673f08970 )>",
    "<NSLayoutConstraint:0x7f8673d623c0 UIView:0x7f8673f08c40.leading == UIView:0x7f8673f08970.leadingMargin + 86>",
    "<NSLayoutConstraint:0x7f8673d7c1e0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f8673f08970(414)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8673d623c0 UIView:0x7f8673f08c40.leading == UIView:0x7f8673f08970.leadingMargin + 86>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2014-12-29 13:00:54.932 Browser_Test[2480:60168] 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:0x7f8673d62b60 H:|-(446)-[UIView:0x7f8673d48640]   (Names: '|':UIView:0x7f8673f08970 )>",
    "<NSLayoutConstraint:0x7f8673d62bb0 UIView:0x7f8673f08970.trailingMargin == UIButton:0x7f8673d53450'5'.trailing + 8>",
    "<NSLayoutConstraint:0x7f8673d62c00 H:[UIView:0x7f8673d48640]-(0)-[UIButton:0x7f8673d53450'5']>",
    "<NSLayoutConstraint:0x7f8673d7c1e0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f8673f08970(414)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8673d62c00 H:[UIView:0x7f8673d48640]-(0)-[UIButton:0x7f8673d53450'5']>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

所以可以请一些人建议我出错了。

修改:1

enter image description here

修改:2

1 个答案:

答案 0 :(得分:0)

按钮应该都有固定宽度。按钮1应设置为通向超视图并且尾随到间隔1.按钮5应设置为通向间隔4并且跟踪到超视图。其他按钮应设置为前导和尾随相邻的垫片。应将所有垫片设置为与垫片1具有相同的宽度。

现在,autolayout将同时调整间隔视图的大小,以填充可用空间,因为它们没有指定的宽度但是按钮有,并且它们也有设置边(对于按钮1和5)。