控制台中出现自动布局的问题

Posted

技术标签:

【中文标题】控制台中出现自动布局的问题【英文标题】:coming the issues of auto layouts in the console 【发布时间】:2014-12-23 11:15:34 【问题描述】:

我正在尝试自动布局概念,这里我在控制台中遇到了更多问题,谁能告诉我如何解决这个问题

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:0x7faeb358e200 H:|-(0)-[UIImageView:0x7faeb35834b0]   (Names: '|':UIView:0x7faeb35832c0 )>",
    "<NSLayoutConstraint:0x7faeb358e390 UILabel:0x7faeb358a1e0'Welcome to'.leading == UIView:0x7faeb35832c0.leadingMargin + 46>",
    "<NSLayoutConstraint:0x7faeb358e4d0 UIImageView:0x7faeb3585ab0.leading == UILabel:0x7faeb358a1e0'Welcome to'.leading + 28>",
    "<NSLayoutConstraint:0x7faeb358e520 UIImageView:0x7faeb3585ab0.leading == UIImageView:0x7faeb35834b0.leading + 90>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7faeb358e390 UILabel:0x7faeb358a1e0'Welcome to'.leading == UIView:0x7faeb35832c0.leadingMargin + 46>

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-23 16:30:57.326 Aaja[11268:148329] Unable to simultaneously satisfy constraints.

这个问题反复出现 10 次

【问题讨论】:

【参考方案1】:

你有这个错误......

|[ImageView-b0]

|-46-[Label-e0]

-(+28)-[ImageView-b0]
[Label-e0]
i.e. |-74-[ImageView-b0] //this conflicts the first one.

[ImageView-b0]
-(+90)-[ImageView-b0]

这些是错误中显示的不同约束。

看起来有点乱。图像视图和超级视图之间的间距为零。然后标签和超级视图之间有 46 个间距。

但随后您尝试将标签和图像视图的左边缘对齐,相差 28。

然后你还有一个我不太明白的问题。您是在告诉它将图像视图的前沿与自身对齐,但有所不同。这将永远无法工作。

它基本上告诉你它不能使所有的约束都起作用,因为它们相互冲突,所以它必须打破其中的一些。

【讨论】:

如何解决这个问题,我对自动布局很困惑

以上是关于控制台中出现自动布局的问题的主要内容,如果未能解决你的问题,请参考以下文章

带有自定义转场的自动布局

自动布局以编程方式导致 iphone 4 出现问题

在storyBoard中禁用单个视图控制器的自动布局

Xcode 在控制台输出中关闭与自动布局相关的警告

视图控制器和自动布局旋转问题

UIView 没有正确定位启用自动布局的故事板