无法同时满足对 UITextField 的约束

Unable to simultaneously satisfy constraints on UITextField

我在调试应用程序时在日志中收到以下信息。视图仍然出现,没有任何问题。如何摆脱这个约束问题?

2019-04-08 13:51:36.006550-0400 Appy[1315:754989] [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:0x28ab90e60 UITextField:0x1082f0a00.width == 247.5   (active)>",
"<NSLayoutConstraint:0x28ab99e50 UITextField:0x1082f0a00.trailing == UITableViewCellContentView:0x10a58b840.trailingMargin - 58.5   (active)>",
"<NSLayoutConstraint:0x28ab99ea0 UITextField:0x1082f0a00.leading == UITableViewCellContentView:0x10a58b840.leadingMargin   (active)>",
"<NSLayoutConstraint:0x28ab9a490 'UIView-Encapsulated-Layout-Width' UITableViewCellContentView:0x10a58b840.width == 600   (active)>",
"<NSLayoutConstraint:0x28ab99f90 'UIView-leftMargin-guide-constraint' H:|-(15)-[UILayoutGuide:0x2835bb800'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':UITableViewCellContentView:0x10a58b840 )>",
"<NSLayoutConstraint:0x28ab9a030 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x2835bb800'UIViewLayoutMarginsGuide']-(15)-|(LTR)   (active, names: '|':UITableViewCellContentView:0x10a58b840 )>"
)

括号中应用后面的值有帮助吗?这是 XIB 生成的某些代码的行号吗?

如果你给宽度约束,你不应该给前导和尾随。要么删除宽度约束,只给出前导和尾随。或者保持宽度,删除leading/trailing。

我建议删除宽度限制并保留文本字段的前导和尾随。

错误说,你给定了一个固定的宽度约束,同时你给了前导和尾随。这两个不能互相满足,因为当你给出前导和尾随时,基于这两个,文本字段的宽度会有所不同。

当 UITextfield 成为第一响应者时,键盘快捷键的 iPad 键盘高度似乎发生了变化(这可能是 Apple 的一个错误)。我这样解决了我的问题:

就在 textField becomeFirstResponder 之前放置此代码:

// Objective-C
[textField becomeFirstResponder];
textField.inputAssistantItem.leadingBarButtonGroups=@[];
textField.inputAssistantItem.trailingBarButtonGroups=@[];

// Swift
let item = textField.inputAssistantItem
item.leadingBarButtonGroups = []
item.trailingBarButtonGroups = []

walla,不再有警告!