xibファイルに次のビューを作成しています。 2つの制約があり、同時にそれらのうちの1つを必要とするため、1つをアクティブにして他の制約を無効にします。Autolayout layoutIfNeededは強制的な制約です
これらの制約の1つは、ビュー(トップレベルビュー)view.bottom == inputView.bottom
です。この制約は、テキスト入力時にユーザーの入力が正しい場合に有効になります。ユーザーが何らかの特殊文字を入力すると、エラーメッセージが表示され、この制約は無効化され、もう1つの制約はview.bottom == errorLabel.bottom
になります。もともと、これらの制約は両方ともxibファイルにありますが、view.bottom == errorLabel.bottom
は750
優先度に設定され、view.bottom == input View.bottom
は必要な優先度1000
に設定されています。これは、矛盾する制約を避けるためです。
ユーザータイプに応じていくつか入力します。
[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
私が上記のコードデバッガを実行すると、壊れた制約の警告が表示されます。
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.
これらの警告は、layoutIfNeeded()
メソッドを呼び出すと表示されます。
私のopenionには、矛盾する制約はありません。しかし、誰かが私を助けることができれば、それは非常にappriciatedされます。あなたの場合、低優先度で
:制約アクティブ状態は前に変更あなたは低い優先度に制約の1つを変更することができます
、
:アドバイスとして
必要に応じてレイアウトをアニメーション化しないでください。制約の変更をアニメーション化してみてください! –
@TejaNandamuri animate 'layoutIfNeeded'は正しい方法です。制約の変更はアニメーション化できません。 – kientux