ios - 我的一个约束有问题

标签 ios swift constraints

我在代码约束方面遇到了一些麻烦 这是我得到的错误

2017-04-08 18:14:36.798 App[465:89996] 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.   ("<_UILayoutSupportConstraint:0x16eb9f00 V:[_UILayoutGuide:0x16d0cb40(64)]>",
"<_UILayoutSupportConstraint:0x16eb2de0 V:|-(0)-[_UILayoutGuide:0x16d0cb40]   (Names: '|':UIView:0x16d32990 )>",
"<NSLayoutConstraint:0x16d06120 V:[_UILayoutGuide:0x16d0cb40]-(0)-[UITableView:0x17ba6e00]>",
"<NSLayoutConstraint:0x16f45f90 V:|-(63.2)-[UITableView:0x17ba6e00]   (Names: '|':UIView:0x16d32990 )>"  ) Will attempt to recover by breaking constraint 

这是我用于约束的代码: 查看加载

let aka = (self.navigationController?.navigationBar.frame.size.height)! + 19.2
holamama = tableView.topAnchor.constraint(equalTo: view.topAnchor, constant: aka)

//This is out of any methods...
var holamama = NSLayoutConstraint()

在我的 UIBUtton 中:

NSLayoutConstraint.activate([holamama])

其他UIButton:

NSLayoutConstraint.deactivate([holamama])

那我该怎么办呢? 谢谢!

最佳答案

因为您没有指定您想要的行为,所以我无法建议更好的方法。不过,我可以帮助解释问题所在。

在这种情况下,错误消息非常有用。它列出了四个约束条件,表明至少有一个是错误的。

"<_UILayoutSupportConstraint:0x16eb9f00 V:[_UILayoutGuide:0x16d0cb40(64)]>",
"<_UILayoutSupportConstraint:0x16eb2de0 V:|-(0)-[_UILayoutGuide:0x16d0cb40]   (Names: '|':UIView:0x16d32990 )>",

这两个约束的类型是_UILayoutSupportConstraint ,这意味着在这种情况下您没有创建它们。它们一起定义了 topLayoutGuide 的位置.因此,它们可能不是问题所在。

"<NSLayoutConstraint:0x16d06120 V:[_UILayoutGuide:0x16d0cb40]-(0)-[UITableView:0x17ba6e00]>",

此约束表示“UITableView 的顶部触及 _UILayoutGuide 的底部。

"<NSLayoutConstraint:0x16f45f90 V:|-(63.2)-[UITableView:0x17ba6e00]   (Names: '|':UIView:0x16d32990 )>"

这是您明确创建的约束。它说“UITableView 的顶部比其父 View 的顶部低 63.2 点。

你明白为什么自动布局会提示吗?你告诉它 UITableView 的顶部必须接触 _UILayoutGuide 的底部, 屏幕顶部下方 64 点,并且还必须屏幕顶部下方 63.2 点。这两个要求是不相容的,因此是错误的。

关于ios - 我的一个约束有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43300992/

相关文章:

ios - 如何使用 Objective-C 在约束条件下绘图

objective-c - 如何使用 NSDateFormatter 将此字符串解析为 NSDate?

iphone - 开胃菜不起作用

ios - 在 UICollectionView 滚动后获取可见项的更新 IndexPath

swift - 如何用 Storyboard呈现类

wolfram-mathematica - 向 Mathematica 指定额外信息以简化表达式

ios - UiPickerView 在其行滚动之前无法工作 ios

jquery - 如何将 div 扩展到浏览器高度或宽度,同时保持其比例? [内图]

swift - 在主视图 Controller 中添加 subview 无法执行按钮单击事件

django - NOT NULL 约束失败 : history. user_id