Unable to simultaneously satisfy constraints while

2019-09-22 01:48发布

问题:

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. (

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

回答1:

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.

Hope this will help :)



回答2:

This is a usual message seen in console when using 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.