-->

无法同时满足约束条件 - 暂时没有限制(Unable to simultaneously satis

2019-07-18 04:58发布

我所经历和删除每一个用户约束但我仍然得到下面的错误后, 只有我旋转设备。 我绝对不知道为什么,虽然。 有没有人有什么想法?

2013-01-14 21:30:31.363 myApp[35869:c07] 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:0x84543d0 h=--& v=--& V:[UIView:0xa330270(768)]>",
    "<NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-|   (Names: '|':UIView:0xa330270 )>",
    "<NSLayoutConstraint:0xa338390 V:|-(841)-[UIView:0xa331260]   (Names: '|':UIView:0xa330270 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-|   (Names: '|':UIView:0xa330270 )>

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.

Answer 1:

让我们来看看这些一个接一个。

"<NSAutoresizingMaskLayoutConstraint:0x84543d0 h=--& v=--& V:[UIView:0xa330270(768)]>"

这话说视图0xa330270(A)必须是768点高。

"<NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-| (Names: '|':UIView:0xa330270 )>"

这话说视图0xa331260(B)的底部边缘必须是从-1 A的底部,这是它的上海华的间隙。

"<NSLayoutConstraint:0xa338390 V:|-(841)-[UIView:0xa331260] (Names: '|':UIView:0xa330270 )>"

这是说,B“顶尖边缘必须的841点从它的父,A的顶部的间隙。

这三样东西不能全是真实的- 一个不能768点高,并包含一个子视图与顶部边缘841点,从顶部嵌入且-1分从底部内侧。 你上哪儿去定义每个约束?

你还没说你想达到什么样的布局,但它看起来像你可能会对这是防止它在高度变化,当你旋转设备的上海华盈的自动尺寸调整掩码。 据我所知道的自动尺寸的限制仅当您以编程方式添加的意见,因为故事板或XIB或者是全自动布局,或不出现。 除非你正在做的事情,如添加了自动布局图(从笔尖装?)另一种观点认为,从非自动布局笔尖?



Answer 2:

感谢http://useYourLoaf.com这个完整的解决方案:

http://useyourloaf.com/blog/using-identifiers-to-debug-autolayout.html

一个快速提示,我发现埋在自动布局一个WWDC 2015年会议的调试与约束问题的时候,可以帮助

如果您已经使用自动布局你会熟悉Xcode中吐出,当你得到一些错误日志。 要创建一个例子,我修改我的筹码查看示例代码 ,并添加了约束在每个图像的给他们的240固定宽度(不是一个好主意,因为我们将看到)。

这一工程在常规宽度意见诸如iPad,但太宽了一个紧凑的宽度视图,如iPhone的肖像。 控制台日志在运行时是不是有趣的阅读。 跳过你的问题的约束列表的样板文字:

"<NSLayoutConstraint:0x7fc1ab520360 H:[UIImageView:0x7fc1ab532650(240)]>",
"<NSLayoutConstraint:0x7fc1ab536ef0 H:[UIImageView:0x7fc1ab537380(240)]>",
"<NSLayoutConstraint:0x7fc1ab545cc0 UIView:0x7fc1ab53d870.trailingMargin == UIStackView:0x7fc1ab53dae0.trailing>",
"<NSLayoutConstraint:0x7fc1ab545d10 UIStackView:0x7fc1ab53dae0.leading == UIView:0x7fc1ab53d870.leadingMargin>",
"<NSLayoutConstraint:0x7fc1ab54e240 'UISV-alignment' UIStackView:0x7fc1ab53dc70.centerX == UIStackView:0x7fc1ab531a10.centerX>",
"<NSLayoutConstraint:0x7fc1ab5167c0 'UISV-canvas-connection' UIStackView:0x7fc1ab531a10.leading == UIImageView:0x7fc1ab532650.leading>",
"<NSLayoutConstraint:0x7fc1ab54ad80 'UISV-canvas-connection' H:[UIImageView:0x7fc1ab537380]-(0)-|   (Names: '|':UIStackView:0x7fc1ab531a10 )>",
"<NSLayoutConstraint:0x7fc1ab5397d0 'UISV-canvas-connection' UIStackView:0x7fc1ab53dae0.leading == _UILayoutSpacer:0x7fc1ab54c3c0'UISV-alignment-spanner'.leading>",
"<NSLayoutConstraint:0x7fc1ab54a4a0 'UISV-canvas-connection' UIStackView:0x7fc1ab53dae0.centerX == UIStackView:0x7fc1ab53dc70.centerX>",
"<NSLayoutConstraint:0x7fc1ab54b110 'UISV-spacing' H:[UIImageView:0x7fc1ab532650]-(16)-[UIImageView:0x7fc1ab537380]>",
"<NSLayoutConstraint:0x7fc1ab548210 'UISV-spanning-boundary' _UILayoutSpacer:0x7fc1ab54c3c0'UISV-alignment-spanner'.leading <= UIStackView:0x7fc1ab531a10.leading>",
"<NSLayoutConstraint:0x7fc1ab551690 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fc1ab53d870(375)]>"

然后,日志会告诉你这上面的约束已经决定分手:

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fc1ab536ef0 H:[UIImageView:0x7fc1ab537380(240)]>

日志输出使用自动布局视觉格式的语言,但它是很难从这些系统创建挑选出我的约束。 这一点尤其与是由设计旨在打造最约束为您堆栈意见的情况。 在这个简单的例子,我知道我刚刚添加的固定宽度的限制打破了东西,但它是很难看到,从日志和越难得到更复杂的看法。

添加标识符的约束

日志变得轻松了很多,如果你添加一个标识符每个约束理解( NSLayoutConstraint以来的iOS 7已经有一个标识属性)。 在Interface Builder中找到的约束,并添加在属性检查器标识符(我使用$作为前缀/后缀,使他们在日志中脱颖而出):

更新18月 - 2015年:作为标识符只能在Interface Builder中进行编辑开始和Xcode 7.评论中指出它不是在Xcode 6.4可见。

如果添加的代码约束:

constraint.identifier = "$HeartImageFixedWidth$"

这是棘手的,如果你正在使用的使用约束的阵列视觉格式的语言。 例如,考虑银行代码片段来创建心脏图像视图的固定宽度约束:

let heartWidth = NSLayoutConstraint.constraintsWithVisualFormat("[heart(240)]", 
                 options:[], metrics:nil, views:viewsDictionary)

由于heartWidth是类型的数组[NSLayoutConstraint]设置所述标识符是一个小更多的工作:

for constraint in heartWidth {
  constraint.identifier = "$HeartImageFixedWidth$"
}
heartImage.addConstraints(heartWidth)

随着我的限制设置标识,现在更容易找到他们在日志文件中(见第4行):

"<NSLayoutConstraint:0x7f92a305aeb0 '$ContainerStackViewLeading$' UIStackView:0x7f92a3053220.leading == UIView:0x7f92a3052fb0.leadingMargin + 32>",
"<NSLayoutConstraint:0x7f92a305b340 '$ContainerStackViewTrailing$' UIView:0x7f92a3052fb0.trailingMargin == UIStackView:0x7f92a3053220.trailing + 32>",
"<NSLayoutConstraint:0x7f92a301cf20 '$HeartImageFixedWidth$' H:[UIImageView:0x7f92a3047ef0(240)]>",
"<NSLayoutConstraint:0x7f92a3009be0 '$StarImageFixedWidth$' H:[UIImageView:0x7f92a304d190(240)]>",
"<NSLayoutConstraint:0x7f92a3060cc0 'UISV-alignment' UIStackView:0x7f92a30533b0.centerX == UIStackView:0x7f92a30472b0.centerX>",
"<NSLayoutConstraint:0x7f92a301c590 'UISV-canvas-connection' UIStackView:0x7f92a30472b0.leading == UIImageView:0x7f92a3047ef0.leading>",
"<NSLayoutConstraint:0x7f92a305f680 'UISV-canvas-connection' H:[UIImageView:0x7f92a304d190]-(0)-|   (Names: '|':UIStackView:0x7f92a30472b0 )>",
"<NSLayoutConstraint:0x7f92a3064190 'UISV-canvas-connection' UIStackView:0x7f92a3053220.leading == _UILayoutSpacer:0x7f92a30608a0'UISV-alignment-spanner'.leading>",
"<NSLayoutConstraint:0x7f92a30415d0 'UISV-canvas-connection' UIStackView:0x7f92a3053220.centerX == UIStackView:0x7f92a30533b0.centerX>",
"<NSLayoutConstraint:0x7f92a305fa10 'UISV-spacing' H:[UIImageView:0x7f92a3047ef0]-(16)-[UIImageView:0x7f92a304d190]>",
"<NSLayoutConstraint:0x7f92a30508c0 'UISV-spanning-boundary' _UILayoutSpacer:0x7f92a30608a0'UISV-alignment-spanner'.leading <= UIStackView:0x7f92a30472b0.leading>",
"<NSLayoutConstraint:0x7f92a3063240 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f92a3052fb0(375)]>"

它也更清晰,系统选择了打破约束:

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f92a3009be0 '$StarImageFixedWidth$' H:[UIImageView:0x7f92a304d190(240)]>

添加标识符来限制也不是没有努力,但它必须通过复杂的布局的调试日志进行排序下一次还清。

延伸阅读

  • WWDC 2015年会话219个自动布局,第2部分之谜


Answer 3:

我想这不是一个常见的错误,但我是个门外汉方式有所解决它。 我是越来越神秘的消息像上面的。 要理解它,我创建的虚拟视图类和它连接到我的故事板视图。 举例来说,如果我有一个UIView,我创建了一个名为AddressView类,它连接到这个观点在故事板。 它有点费时,但它为我工作。 在此之后,而不是对象ID,我得到了类名这让我​​在零上是非常容易造成问题的看法。 现在读我的错误信息,

2013-07-02 04:16:20.434 Myproject [2908:c07] 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:0x9edeae0 V:|-(0)-[AddressView:0x143ee020]   (Names: '|':MainView:0x129eb6a0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x11e998c0 h=--& v=--& V:[MainView:0x129eb6a0(704)]>",
    "<NSLayoutConstraint:0x156720b0 V:[AddressView:0x143ee020]-(896)-|   (Names: '|':MainView:0x129eb6a0 )>"
)

在这里你可以看到,我的意见的MainView和地址视图的名字引起的问题。

要解决这个问题,我只是提出我的子视图(在这种情况下地址视图)和重新回来。 我认为这个问题开始,因为我是用新的自动Layour的混合在Xcode 4.5和老技能或手动定位的意见。

不管怎么说,不知道这是否是比勤奋更运气,但无论如何,这可能是调试的方式不同。 也许这可以帮助别人!



Answer 4:

它值得了解的基础知识,并了解苹果/ Xcode是试图通过日志来告诉你

H = Horizontal constraint(for leading and Trailing)
V = Vertical constraint(top and bottom edge)
h = height
w = width

TopEdge    -> V:|-(points)-[VIEW:memoryAddress] 
BottomEdge -> V:[VIEW:memoryAddress]-(points)-|
Leading    -> H:|-(points)-[VIEW:memoryAddress] 
Trailing   -> H:[VIEW:memoryAddress] -(points)-|
height     -> h= --& v=--& V:[VIEW:memoryAddress((points)] 
width      -> VIEW:memoryAddress.width == points 
between    -> H:[VIEW 1]-(51)-[VIEW 2] 

一旦你理解了这一点,读你的特定错误是很容易的



Answer 5:

YourConstraintView.translatesAutoresizingMaskIntoConstraints = NO;

这样做是为了我。



Answer 6:

我已经解决了这个问题,可以从删除厦门国际银行文件中的所有translatesAutoresizingMaskIntoConstraints属性(厦门国际银行开放的源代码)。



Answer 7:

一个音符。 您在日志中得到这个错误,如果您使用的是个人热点连接测试,以及热点状态栏在顶部。 它抛出了约束。

希望这可以帮助别人..被我逼疯。



Answer 8:

对我来说,当我把这个错误被吐唾沫tableView.estimatedRowHeight = UITableViewAutomaticDimension

这本来tableView.estimatedRowHeight = "Some hardcoded value"



Answer 9:

我有这个问题,我花了2天,找出问题的根源....

如果你在你的代码编程方式打开一个故事板只要确保你做这样的:

UIStoryboard *story = [UIStoryboard storyboardWithName:@"MovieMaker" bundle:nil];
    UIViewController *vc = [story instantiateInitialViewController];
    //this causes layout to break [self presentViewController:vc animated:YES completion:nil];
    [self showViewController:vc sender:nil];

我使用(使用presentViewController)的注释行和方向错误已经发生,这不是我的限制...更改为showViewController所有约束矛盾都不见了和方向投掷工作冲突的限制......(我不知道知道为什么它展示,而不是现在的作品...仍然认为它是......外星人...;)



Answer 10:

生成的消息“无法同时满足约束上”在调试控制台中的这个问题,也经历了XCode 9.4。
在iPad上的模拟器我的特殊情况下,该消息将产生:
1)将重点放在特定的UITextField只有当。
2)即使所有视图约束上除去。
2)即使所有视图约束上“复位到推荐约束上”。

然而,当软件键盘被切换到显示,不会产生设备的消息。 因此,多少时间,我应该把钱花在这个问题上,在我的情况下,当软键盘切换关闭时,才会生成。



文章来源: Unable to simultaneously satisfy constraints - No constraints in place