通过UITextFields约束问题进行交换



我有一个EditProfileViewController,它有一个表视图和文本字段。在其中一个文本字段中,我有一个pickerView作为inputView,inputAccessoryView中有一个工具栏。当视图加载时,我选择firstName文本字段,然后返回并移动到lastName文本字段时,我会得到一个约束警告。

[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. 
(
"<NSLayoutConstraint:0x2809a4640 'assistantHeight' TUISystemInputAssistantView:0x1113b11a0.height == 45   (active)>",
"<NSLayoutConstraint:0x2809a0320 'assistantView.bottom' TUISystemInputAssistantView:0x1113b11a0.bottom == _UIKBCompatInputView:0x11a437e80.top   (active)>",
"<NSLayoutConstraint:0x2809a05a0 'assistantView.top' V:|-(0)-[TUISystemInputAssistantView:0x1113b11a0]   (active, names: '|':UIInputSetHostView:0x11d06ce50 )>",
"<NSLayoutConstraint:0x280943840 'inputView.top' V:|-(0)-[_UIKBCompatInputView:0x11a437e80]   (active, names: '|':UIInputSetHostView:0x11d06ce50 )>"
)
Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x2809a0320 'assistantView.bottom' TUISystemInputAssistantView:0x1113b11a0.bottom == _UIKBCompatInputView:0x11a437e80.top   (active)>

当我在两个默认文本字段之间切换时,会发生这种情况,我不明白为什么。我做了一些研究,从我所看到的情况来看,这是iOS 13的一个错误,因为在另一台iOS 10的设备上,这种情况并没有发生。

删除此约束问题的解决方法是将autoCorrectionType设置为false。但我希望启用此功能。我想发生这种情况是因为我在countryText字段的inputView中有一个pickerView,但我不知道如何解决这个问题。

这是在我的iOS13应用程序中开始发生的,我怀疑这是一个错误。在尝试了我能想到的一切之后,我关闭了自动更正,不再遇到约束问题。

textEdit.autocorrectionType = .no

试试这个

  • 如果您已经从故事板中添加了pickerView,请将其删除
  • 使pickerView.translatesAutoresizingMaskIntoConstraints=false

因为我们不希望在inputView上有任何约束,但AutoresizingMask获得了冲突的默认空间as约束。

我是第一次在这里回答,所以如果出了问题,我很抱歉。

潜在的快速修复:

对于约束错误,我可能有一个快速的解决方案-确保您将键盘设置为

更正:否智能插入:无

最新更新