简体   繁体   English

以编程方式应用自动布局约束时无法同时满足约束

[英]Unable to simultaneously satisfy constraints while applying auto layout constraints programatically

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; (1) 查看每个约束并尝试找出您不期望的;

(2) find the code that added the unwanted constraint or constraints and fix it. (2) 找到添加不需要的约束或约束的代码并修复它。 ( (

"<NSLayoutConstraint:0x7f844b716390 H:|-(30)-[UIButton:0x7f844b4be3c0'LOGIN']   (Names: '|':UIView:0x7f844b492a80 )>",
    "<NSLayoutConstraint:0x7f844b706ee0 H:[UIButton:0x7f844b4be3c0'LOGIN'(100)]>",
    "<NSLayoutConstraint:0x7f844b705dd0 H:[UIButton:0x7f844b4be3c0'LOGIN']-(80)-[UIButton:0x7f844b4c0520'SIGNUP']>",
    "<NSLayoutConstraint:0x7f844b706f30 H:[UIButton:0x7f844b4c0520'SIGNUP'(100)]>",
    "<NSLayoutConstraint:0x7f844b7147c0 H:[UIButton:0x7f844b4c0520'SIGNUP']-(30)-|   (Names: '|':UIView:0x7f844b492a80 )>",
    "<NSLayoutConstraint:0x7f844b519f70 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f844b492a80(375)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f844b705dd0 H:[UIButton:0x7f844b4be3c0'LOGIN']-(80)-[UIButton:0x7f844b4c0520'SIGNUP']>

That means your constraints is not satisfy from every point of view.这意味着您的约束并非从每个角度都满足。 for example if you have view with 50x50 size.例如,如果您有 50x50 大小的视图。 and it is positioned at exact center.它位于精确的中心。 now if you give constraints like horizontaly center in container and leading constraint like always keep 0 distance with leading edge (left edge) then it creates ambiguity.现在,如果您在容器中设置水平中心等约束,并在前导约束中始终与前缘(左边缘)保持0距离,则会产生歧义。 it can't satisfy both constraints.它不能同时满足这两个约束。 whether it can remains in center or it can manage 0 distance with leading edge but both can't satisfy so this give error like unable to simultaneously satisfy constraints .它是否可以保持在中心或它可以管理与前缘的 0 距离,但两者都不能满足,所以这会导致unable to simultaneously satisfy constraints等错误。

So, in your case check your all related constraints.因此,在您的情况下,请检查所有相关约束。 If any constraints ambiguity then remove it and any constrain is missing then add it.如果任何约束不明确,则将其删除,并且缺少任何约束,然后添加它。

Hope this will help :)希望这会有所帮助:)

This is a usual message seen in console when using Autolayout.这是使用 Autolayout 时在控制台中看到的常见消息。 This is caused by some mistakes you have made while creating constraints for you view objects.这是由您在为视图对象创建约束时犯的一些错误造成的。 Check every constraints carefully.仔细检查每个约束。 The view may render properly at this time.此时视图可能会正确呈现。 But on different device with different screen sizes and orientations, the view may break.但是在具有不同屏幕尺寸和方向的不同设备上,视图可能会中断。 You may have missed one or two constraints for a view, added ambiguous constraints for a view etc.您可能错过了一个视图的一两个约束,为视图添加了不明确的约束等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM