无法同时满足UITextField

时间:2019-04-08 18:02:02

标签: ios ios-autolayout

调试应用程序时,日志中显示以下内容。该视图仍然出现,并且没有错。如何摆脱这个约束问题?

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生成的某些代码的行号吗?

2 个答案:

答案 0 :(得分:3)

如果给出宽度约束,则不应给出前导和尾随。要么删除宽度约束,然后给出前导和尾随。或保持宽度,然后删除前导/尾随。

我建议删除宽度约束,并保留文本字段的开头和结尾。

该错误表明,您已给定了固定的宽度约束,同时又给出了前导和尾随。这两个不能彼此满足,因为当您给出前导和尾随时,基于这两个,文本字段的宽度将有所不同。

答案 1 :(得分:0)

当 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,不再有警告!