Sunday, September 24, 2017

[LayoutConstraints] Unable to simultaneously satisfy constraints

I'm learning Swift 3 by using Xcode 8 on MacOS Sierra. My view controller has a simple button, and I created two constraints for the top space and bottom space of the button. When I launch the app in Xcode, I got the following log message.

2017-09-24 16:40:23.780953+0700 Learn Swift[31177:1017369] [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.
(
    "<_UILayoutSupportConstraint:0x600000090770 _UILayoutGuide:0x7ff359716960.height == 0   (active)>",
    "<_UILayoutSupportConstraint:0x60000008eb00 V:|-(0)-[_UILayoutGuide:0x7ff359716960]   (active, names: '|':UIView:0x7ff359715f40 )>",
    "<_UILayoutSupportConstraint:0x6000000906d0 _UILayoutGuide:0x7ff359716b20.height == 0   (active)>",
    "<_UILayoutSupportConstraint:0x600000090720 _UILayoutGuide:0x7ff359716b20.bottom == UIView:0x7ff359715f40.bottom   (active)>",
    "<NSLayoutConstraint:0x600000090950 V:[_UILayoutGuide:0x7ff359716960]-(113)-[NextButton]   (active, names: NextButton:0x7ff359716370 )>",
    "<NSLayoutConstraint:0x6000000909a0 V:[NextButton]-(465)-[_UILayoutGuide:0x7ff359716b20]   (active, names: NextButton:0x7ff359716370 )>",
    "<NSLayoutConstraint:0x60800008d430 'UIView-Encapsulated-Layout-Height' UIView:0x7ff359715f40.height == 568   (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000000909a0 V:[NextButton]-(465)-[_UILayoutGuide:0x7ff359716b20]   (active, names: NextButton:0x7ff359716370 )>
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.
There is a conflict between the constraints i created and the constraint the system created by default for the button. The height of the view controller's view is only 568 points, which is less than the sum of the button's height (29 points), top space (113 points), and bottom space (465 points). 

According to this page, we should lower the priority of the bottom space constraint (465 points) to 999 so the system will provide the selected bottom space, which is as close as it can while still satisfying the other constraints. 




No comments:

Post a Comment