Just started learning iOS AutoLayout, Interface builder very straight forward, but when I try to archive the same thing on the code
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(==2)-[_nextKeyboardButton]-(==2)-[_numPadButton]-(==2)-[_spaceButton]-(==2)-[_returnButton]-(==2)-|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_nextKeyboardButton,_numPadButton,_spaceButton,_returnButton)]];
it raises an exception,
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:0x6000000966c0 H:|-(2)-[UIButton:0x7fe4f1d1c760'Next'] (Names: '|':UIInputView:0x7fe4f1f04d00 )>", "<NSLayoutConstraint:0x600000096710 H:[UIButton:0x7fe4f1d1c760'Next']-(2)-[UIButton:0x7fe4f1d1d1d0'123']>", "<NSLayoutConstraint:0x600000096760 H:[UIButton:0x7fe4f1d1d1d0'123']-(2)-[UIButton:0x7fe4f1d1d6f0'Space']>", "<NSLayoutConstraint:0x6000000967b0 H:[UIButton:0x7fe4f1d1d6f0'Space']-(2)-[UIButton:0x7fe4f1d1d8d0'Return']>", "<NSLayoutConstraint:0x600000096800 H:[UIButton:0x7fe4f1d1d8d0'Return']-(2)-| (Names: '|':UIInputView:0x7fe4f1f04d00 )>", "<NSLayoutConstraint:0x600000096e40 'UIView-Encapsulated-Layout-Width' H:[UIInputView:0x7fe4f1f04d00(0)]>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x6000000967b0 H:[UIButton:0x7fe4f1d1d6f0'Space']-(2)-[UIButton:0x7fe4f1d1d8d0'Return']>
All 4 buttons .translatesAutoresizingMaskIntoConstraints = NO;
I wonder what is wrong ? help is really appreciated :)
FYI: I work on iOS8 SDK
The easiest way how to find unsatisfiable constraints:
NSLayoutConstraint
:SWIFT:
extension NSLayoutConstraint { override public var description: String { let id = identifier ?? "" return "id: \(id), constant: \(constant)" //you may print whatever you want here } }
OBJECTIVE-C
@interface NSLayoutConstraint (Description) @end @implementation NSLayoutConstraint (Description) -(NSString *)description { return [NSString stringWithFormat:@"id: %@, constant: %f", self.identifier, self.constant]; } @end
id
you can simple tap it in your Find Navigator:HOW TO SIMPLE FIX THAT CASE?
999
for broken constraint.See the related answer here: Unable to simultaneously satisfy constraints, will attempt to recover by breaking constraint
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With