_UIButtonBarStackView:当sentFirstResponder发送时打破约束 [英] _UIButtonBarStackView: breaking constraint when becomeFirstResponder sent
问题描述
从一个文本域跳转到另一个文本域时,得到:
translatesAutoresizingMaskIntoConstraints)
(
< NSAutoresizingMaskLayoutConstraint:0x6040002806e0 UIKeyboardAssistantBar:0x7f986d40d020.height == 0>,
< NSLayoutConstraint:0x60400008ece0 _UIButtonBarStackView:0x7f986d4041c0.top == UIKeyboardAssistantBar:0x7f986d40d020.top>,
< NSLayoutConstraint :0x60400008ed30 UIKeyboardAssistantBar:0x7f986d40d020.bottom == _UIButtonBarStackView:0x7f986d4041c0.bottom> 中,
的< NSLayoutConstraint:0x60400009f220 _UIButtonBarButton:0x7f986d438480.height == UILayoutGuide:0x6040005b5ee0.height> 中,
的< NSLayoutConstraint :0x60400008e1a0 _UIButtonBarStackView:0x7f986d4041c0.bottom == UILayoutGuide:0x6040005b5ee0.bottom + 9>,
< NSLayoutConstraint:0x60400008e100 UILayoutGuide:0x6040005b5ee0.top == _UIButtonBarStackView:0x7f986d4041c0.top + 10>
)
将尝试通过bre恢复aking约束
< NSLayoutConstraint:0x60400008e1a0 _UIButtonBarStackView:0x7f986d4041c0.bottom == UILayoutGuide:0x6040005b5ee0.bottom + 9>
在UIViewAlertForUnsatisfiableConstraints上创建一个符号断点,以便在调试器中捕获它。
< UIKit / UIView.h>中列出的UIView上的UIConstraintBasedLayoutDebugging类别中的方法也可能有所帮助。
在模拟器中测试,不要使用设备。键盘上
我的超级简单代码触发违约:
- (BOOL)textFieldShouldReturn: (UITextField *)textField
{
[textField resignFirstResponder];
if(textField.tag> 0){
UITextField * nextTextField = [self.view viewWithTag:textField.tag + 1];
[nextTextField becomeFirstResponder];
}
返回YES;
}
这个警告让我恼火很长一段时间我通过清空 inputAssistantItem <上的
leadingBarButtonGroups
和 trailingBarButtonGroups
发现了两行'hack' / code> UITextField上的属性:
inputAssistantItem.leadingBarButtonGroups = []
inputAssistantItem.trailingBarButtonGroups = [ ]
这可以在调用时控制UIKeyboardAssistantBar AutoLayout警告
becomeFirstResonder()
此处有更多信息: https://developer.apple.com/documentation/uikit/uitextinputassistantitem
Apple的特定说明:
要完全隐藏快捷方式,请将leadingBarButtonGroups和trailingBarButtonGroups属性设置为nil。
When jumping from one textfield to an other, get this:
translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x6040002806e0 UIKeyboardAssistantBar:0x7f986d40d020.height == 0>",
"<NSLayoutConstraint:0x60400008ece0 _UIButtonBarStackView:0x7f986d4041c0.top == UIKeyboardAssistantBar:0x7f986d40d020.top>",
"<NSLayoutConstraint:0x60400008ed30 UIKeyboardAssistantBar:0x7f986d40d020.bottom == _UIButtonBarStackView:0x7f986d4041c0.bottom>",
"<NSLayoutConstraint:0x60400009f220 _UIButtonBarButton:0x7f986d438480.height == UILayoutGuide:0x6040005b5ee0.height>",
"<NSLayoutConstraint:0x60400008e1a0 _UIButtonBarStackView:0x7f986d4041c0.bottom == UILayoutGuide:0x6040005b5ee0.bottom + 9>",
"<NSLayoutConstraint:0x60400008e100 UILayoutGuide:0x6040005b5ee0.top == _UIButtonBarStackView:0x7f986d4041c0.top + 10>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400008e1a0 _UIButtonBarStackView:0x7f986d4041c0.bottom == UILayoutGuide:0x6040005b5ee0.bottom + 9>
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.
Testing in simulator, do not get on device. Something wrong with shortcuts bar over keyboard1?
My super easy code triggers breaking constraint:
-(BOOL)textFieldShouldReturn:(UITextField*)textField
{
[textField resignFirstResponder];
if (textField.tag > 0) {
UITextField *nextTextField = [self.view viewWithTag:textField.tag+1];
[nextTextField becomeFirstResponder];
}
return YES;
}
This warning has annoyed me for quite some time. I discovered a two-line 'hack' by emptying leadingBarButtonGroups
and trailingBarButtonGroups
on the inputAssistantItem
property on the UITextField:
inputAssistantItem.leadingBarButtonGroups = []
inputAssistantItem.trailingBarButtonGroups = []
This controls the UIKeyboardAssistantBar AutoLayout warnings when calling
becomeFirstResonder()
More info here: https://developer.apple.com/documentation/uikit/uitextinputassistantitem
Specific note from Apple:
To hide shortcuts altogether, set the leadingBarButtonGroups and trailingBarButtonGroups properties to nil.
这篇关于_UIButtonBarStackView:当sentFirstResponder发送时打破约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!