Ich erstelle die folgende Ansicht in der XIB-Datei. Es gibt zwei Constraint und ich möchte einen von ihnen gleichzeitig, also aktiviere ich einen und deaktiviere andere Constraint.Autolayout layoutIfNeeded bricht Einschränkungen
Eine dieser Einschränkungen ist View (Toplevel-Ansicht) view.bottom == inputView.bottom
. Diese Einschränkung ist aktiviert, wenn die Benutzereingabe in der Textansicht korrekt ist. Wenn ein Benutzer ein Sonderzeichen eingibt, wird eine Fehlermeldung angezeigt, und diese Einschränkung wird deaktiviert, und eine weitere Einschränkung, die view.bottom == errorLabel.bottom
ist, wird aktiviert. Ursprünglich sind beide Bedingungen in der XIB-Datei vorhanden, aber view.bottom == errorLabel.bottom
ist 750
Priorität und view.bottom == input View.bottom
ist mit der erforderlichen Priorität 1000
festgelegt. Dies dient dazu, widersprüchliche Einschränkungen zu vermeiden.
Jetzt als Benutzer geben Sie einige Eingabe ich folgende.
[NSLayoutConstraint deactivateConstraints:@[self.inputViewConstraint, self.inputViewWithErrorConstraint]];
self.inputViewConstraint.active = (result == NBValidationResultOK);
self.inputViewWithErrorConstraint.active = !self.inputViewConstraint.active;
[UIView animateWithDuration:0.1 animations:^{
[self layoutIfNeeded];
}];
inputViewConstraint -----> view.bottom == InputView.bottom
inputViewWithErrorConstraint -----> view.bottom == errorLabel.bottom
Wenn ich obigen Code Debugger ausführen gibt mir Breaking Constraints Warnungen.
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.
2016-08-09 17:11:45.181 NB[17707:1811620] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x7faf12ac8850 h=-&- v=-&- UIView:0x7faf12ac41f0.width == NBSendMoneyTextInputView:0x7faf128c8ab0.width>",
"<NSLayoutConstraint:0x7faf12a74020 H:|-(16)-[NBUISecondaryLabel:0x7faf12ac3560'SecondaryLabel'] (Names: '|':UIView:0x7faf12ac31e0)>",
"<NSLayoutConstraint:0x7faf12a4a950 UITextView:0x7faf140b7400.leading == NBUISecondaryLabel:0x7faf12ac3560'SecondaryLabel'.leading>",
"<NSLayoutConstraint:0x7faf12a76630 H:[UITextView:0x7faf140b7400]-(16)-| (Names: '|':UIView:0x7faf12ac31e0)>",
"<NSLayoutConstraint:0x7faf12a2ae80 H:[UIView:0x7faf12ac31e0]-(0)-| (Names: '|':UIView:0x7faf12ac41f0)>",
"<NSLayoutConstraint:0x7faf12a2aed0 H:|-(0)-[UIView:0x7faf12ac31e0] (Names: '|':UIView:0x7faf12ac41f0)>",
"<NSLayoutConstraint:0x7faf12ac5ac0 '_UITemporaryLayoutWidth' H:[NBSendMoneyTextInputView:0x7faf128c8ab0(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7faf12a4a950 UITextView:0x7faf140b7400.leading == NBUISecondaryLabel:0x7faf12ac3560'SecondaryLabel'.leading>
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.
2016-08-09 17:11:45.182 NB[17707:1811620] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x7faf12ac88f0 h=-&- v=-&- UIView:0x7faf12ac41f0.height == NBSendMoneyTextInputView:0x7faf128c8ab0.height>",
"<NSLayoutConstraint:0x7faf12aa8b20 V:[NBUISeparatorView:0x7faf12ac3990(2)]>",
"<NSLayoutConstraint:0x7faf12a64b10 V:|-(18)-[NBUISecondaryLabel:0x7faf12ac3560'SecondaryLabel'] (Names: '|':UIView:0x7faf12ac31e0)>",
"<NSLayoutConstraint:0x7faf12a368b0 V:[NBUISecondaryLabel:0x7faf12ac3560'SecondaryLabel']-(4)-[UITextView:0x7faf140b7400]>",
"<NSLayoutConstraint:0x7faf12a41f60 V:[UITextView:0x7faf140b7400]-(2)-[NBUISeparatorView:0x7faf12ac3990]>",
"<NSLayoutConstraint:0x7faf12a3e240 V:[NBUISeparatorView:0x7faf12ac3990]-(0)-| (Names: '|':UIView:0x7faf12ac31e0)>",
"<NSLayoutConstraint:0x7faf12a211e0 V:|-(0)-[UIView:0x7faf12ac31e0] (Names: '|':UIView:0x7faf12ac41f0)>",
"<NSLayoutConstraint:0x7faf12a9ba30 V:[UIView:0x7faf12ac31e0]-(0)-| (Names: '|':UIView:0x7faf12ac41f0)>",
"<NSLayoutConstraint:0x7faf12ac5bf0 '_UITemporaryLayoutHeight' V:[NBSendMoneyTextInputView:0x7faf128c8ab0(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7faf12aa8b20 V:[NBUISeparatorView:0x7faf12ac3990(2)]>
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.
2016-08-09 17:11:45.196 NB[17707:1811620] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x7faf12ac88f0 h=-&- v=-&- UIView:0x7faf12ac41f0.height == NBSendMoneyTextInputView:0x7faf128c8ab0.height>",
"<NSLayoutConstraint:0x7faf12a64b10 V:|-(18)-[NBUISecondaryLabel:0x7faf12ac3560'SecondaryLabel'] (Names: '|':UIView:0x7faf12ac31e0)>",
"<NSLayoutConstraint:0x7faf12a368b0 V:[NBUISecondaryLabel:0x7faf12ac3560'SecondaryLabel']-(4)-[UITextView:0x7faf140b7400]>",
"<NSLayoutConstraint:0x7faf12a41f60 V:[UITextView:0x7faf140b7400]-(2)-[NBUISeparatorView:0x7faf12ac3990]>",
"<NSLayoutConstraint:0x7faf12a3e240 V:[NBUISeparatorView:0x7faf12ac3990]-(0)-| (Names: '|':UIView:0x7faf12ac31e0)>",
"<NSLayoutConstraint:0x7faf12a211e0 V:|-(0)-[UIView:0x7faf12ac31e0] (Names: '|':UIView:0x7faf12ac41f0)>",
"<NSLayoutConstraint:0x7faf12a9ba30 V:[UIView:0x7faf12ac31e0]-(0)-| (Names: '|':UIView:0x7faf12ac41f0)>",
"<NSLayoutConstraint:0x7faf12ac5bf0 '_UITemporaryLayoutHeight' V:[NBSendMoneyTextInputView:0x7faf128c8ab0(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7faf12a368b0 V:[NBUISecondaryLabel:0x7faf12ac3560'SecondaryLabel']-(4)-[UITextView:0x7faf140b7400]>
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.
Bitte beachten Sie, dass diese Warnungen nur, wenn ich layoutIfNeeded()
Methode aufrufen, erscheinen.
In meinem Openion gibt es keine widersprüchlichen Einschränkungen. Aber wenn jemand mir helfen kann, wird das sehr geschätzt.
sollten Sie das Layout bei Bedarf nicht animieren. Versuchen Sie, die Änderung der Struktur zu animieren! –
@TejaNandamuri animieren 'layoutIfNeeded' ist der richtige Weg. Constraint-Änderung ist nicht animierbar. – kientux