iOS "Unable to simultaneously satisfy constraints"
iOS "Unable to simultaneously satisfy constraints"
我将使用以下符号来解释涉及的视图:
- {V} – “superview”,即根控制器的主视图
- {Q} – 屏幕中央的矩形,用作测验
- {W} – {Q}上方的白色条
在 iPad-Air2 模拟器上 运行 时,我得到以下输出:
2016-11-03 08:09:07.700117 MyApp[16645:6976134] [LayoutConstraints] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x60000009d600 h=--& v=--& QuizButtons:0x7fcb8e521830.width == 717 (active)>",
"<NSLayoutConstraint:0x608000281fe0 H:|-(0)-[ImgWhiteBar:0x7fcb8e525020] (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>",
"<NSLayoutConstraint:0x6080002820d0 H:[ImgWhiteBar:0x7fcb8e525020]-(0)-| (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>",
"<NSLayoutConstraint:0x608000282210 ImgWhiteBar:0x7fcb8e525020.width == 1.07143*QuizButtons:0x7fcb8e521830.width (active)>",
"<NSLayoutConstraint:0x60000009b9e0 'UIView-Encapsulated-Layout-Width' ViewTestVC:0x7fcb8e639b30.width == 768 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6080002820d0 H:[ImgWhiteBar:0x7fcb8e525020]-(0)-| (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>
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.
我对记录约束的解释是:
- {Q}:默认
<h=--& v=--&>
,宽度=717
- 水平:{V.lead} -0- {W}
- 水平:{W} -0- {V.trail}
- {W.width} = 1.07 * {Q.width}
- {V.width} = 768
或者更简单一些
- {Q.width} 必须是 717
- {W.width} 必须是 768.21531
- {W} 必须触及 {V} 的两边
- {V.width} = 768
问题:
- 我的解释正确吗?
- 这里有什么问题?这是由于 768.2 与 768 的不准确?如果是,谁让Xcode使用717?我告诉 {Q.width} 是 {W.width}/[14:15]
在此感谢任何帮助!
编辑
以下是三个约束条件:
冲突约束列表包括 h=--& v=--&
,这是默认的非自动布局形式。
我尝试使用自动布局获取初始大小和位置,然后尝试通过设置 translatesAutoresizingMaskIntoConstraints=YES 关闭自动布局。我在 Apple 开发者论坛上得到了一个答案,说在这种情况下我需要删除视图的所有约束,可能是从超级视图中删除并添加回去。
提示
在调查这个错误时,我找到了一种使约束冲突日志更容易理解的方法。问题是视图显示为匿名,仅指定 class 而未指定名称。
为了使您的视图可识别,打开您的一个 .m
文件并为您想要识别的每个视图添加一个新的 class,就像这样:
@interface ImgWhiteBar: UIImageView
@end
@implementation ImgWhiteBar
@end
@interface Spacer1: UIView
@end
@implementation Spacer1
@end
之后,在InterfaceBuilder中,select每个视图,然后在"Identity Inspector"右边修改泛型class(UIVIew,UIImageView等)成其中之一class是您刚刚创建的。
现在再次 运行 和 Abracadabra - 所有视图现在都用它们的自定义 class 标识,让您了解那里发生了什么。
祝你调试约束愉快!
我将使用以下符号来解释涉及的视图:
- {V} – “superview”,即根控制器的主视图
- {Q} – 屏幕中央的矩形,用作测验
- {W} – {Q}上方的白色条
在 iPad-Air2 模拟器上 运行 时,我得到以下输出:
2016-11-03 08:09:07.700117 MyApp[16645:6976134] [LayoutConstraints] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x60000009d600 h=--& v=--& QuizButtons:0x7fcb8e521830.width == 717 (active)>",
"<NSLayoutConstraint:0x608000281fe0 H:|-(0)-[ImgWhiteBar:0x7fcb8e525020] (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>",
"<NSLayoutConstraint:0x6080002820d0 H:[ImgWhiteBar:0x7fcb8e525020]-(0)-| (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>",
"<NSLayoutConstraint:0x608000282210 ImgWhiteBar:0x7fcb8e525020.width == 1.07143*QuizButtons:0x7fcb8e521830.width (active)>",
"<NSLayoutConstraint:0x60000009b9e0 'UIView-Encapsulated-Layout-Width' ViewTestVC:0x7fcb8e639b30.width == 768 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6080002820d0 H:[ImgWhiteBar:0x7fcb8e525020]-(0)-| (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>
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.
我对记录约束的解释是:
- {Q}:默认
<h=--& v=--&>
,宽度=717 - 水平:{V.lead} -0- {W}
- 水平:{W} -0- {V.trail}
- {W.width} = 1.07 * {Q.width}
- {V.width} = 768
或者更简单一些
- {Q.width} 必须是 717
- {W.width} 必须是 768.21531
- {W} 必须触及 {V} 的两边
- {V.width} = 768
问题:
- 我的解释正确吗?
- 这里有什么问题?这是由于 768.2 与 768 的不准确?如果是,谁让Xcode使用717?我告诉 {Q.width} 是 {W.width}/[14:15]
在此感谢任何帮助!
编辑
以下是三个约束条件:
冲突约束列表包括 h=--& v=--&
,这是默认的非自动布局形式。
我尝试使用自动布局获取初始大小和位置,然后尝试通过设置 translatesAutoresizingMaskIntoConstraints=YES 关闭自动布局。我在 Apple 开发者论坛上得到了一个答案,说在这种情况下我需要删除视图的所有约束,可能是从超级视图中删除并添加回去。
提示
在调查这个错误时,我找到了一种使约束冲突日志更容易理解的方法。问题是视图显示为匿名,仅指定 class 而未指定名称。
为了使您的视图可识别,打开您的一个 .m
文件并为您想要识别的每个视图添加一个新的 class,就像这样:
@interface ImgWhiteBar: UIImageView
@end
@implementation ImgWhiteBar
@end
@interface Spacer1: UIView
@end
@implementation Spacer1
@end
之后,在InterfaceBuilder中,select每个视图,然后在"Identity Inspector"右边修改泛型class(UIVIew,UIImageView等)成其中之一class是您刚刚创建的。
现在再次 运行 和 Abracadabra - 所有视图现在都用它们的自定义 class 标识,让您了解那里发生了什么。
祝你调试约束愉快!