以编程方式应用自动布局约束时无法同时满足约束 [英] Unable to simultaneously satisfy constraints while applying auto layout constraints programatically

查看:52
本文介绍了以编程方式应用自动布局约束时无法同时满足约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法同时满足约束条件.可能以下列表中的至少一项约束是您不想要的.

Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want.

试试这个:

(1) 查看每个约束并尝试找出您不期望的;

(1) look at each constraint and try to figure out which you don't expect;

(2) 找到添加了不需要的约束或约束的代码并修复它.(

(2) find the code that added the unwanted constraint or constraints and fix it. (

"<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']>

推荐答案

这意味着您的约束并非从每个角度都满足.例如,如果您有 50x50 大小的视图.它位于精确的中心.现在,如果您在容器中提供水平中心等约束和始终保持 0 与前缘(左边缘)距离的前导约束,则会产生歧义.它不能同时满足这两个约束.它是否可以保持在中心或它可以管理与前沿的 0 距离但两者都不能满足所以这会导致 无法同时满足约束这样的错误.

That means your constraints is not satisfy from every point of view. for example if you have view with 50x50 size. 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. 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.

因此,在您的情况下,请检查所有相关约束.如果任何约束不明确,则将其删除,如果缺少任何约束,则添加它.

So, in your case check your all related constraints. If any constraints ambiguity then remove it and any constrain is missing then add it.

希望这会有所帮助:)

这篇关于以编程方式应用自动布局约束时无法同时满足约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆