Ios 更新约束在UITableView snapkit上不起作用

Ios 更新约束在UITableView snapkit上不起作用,ios,swift,uitableview,snapkit,Ios,Swift,Uitableview,Snapkit,当我尝试在创建约束后立即更新snapkit约束时,我得到一个更新的约束无法找到要更新的现有匹配约束错误。我使用的代码如下: let directionList = UITableView() directionList.delegate = self directionList.dataSource = self directionList.tag = DIRECTIONS_TABLE_TAG self.view.addSubview(directionList) directionList.s

当我尝试在创建约束后立即更新snapkit约束时,我得到一个
更新的约束无法找到要更新的现有匹配约束
错误。我使用的代码如下:

let directionList = UITableView()
directionList.delegate = self
directionList.dataSource = self
directionList.tag = DIRECTIONS_TABLE_TAG
self.view.addSubview(directionList)
directionList.snp.makeConstraints{ (make) -> Void in
    make.width.equalToSuperview()
    make.top.equalTo(self.view.snp.bottom)
    make.left.equalToSuperview()
    make.right.equalToSuperview()
    make.bottom.equalToSuperview().offset(-20)
}

directionList.snp.updateConstraints { (make) -> Void in
   make.top.equalTo(self.topDarkBlue.snp.bottom)
}
声明UpdateConstraint仅用于更新现有约束的常量

如果仅更新 约束您可以使用snp.updateConstraints方法代替 snp.makeConstraints

您没有更新常量;您正在尝试将约束指定给新的定位点

我认为您应该做的是参考顶部约束:

var topConstraint: Constraint? = nil
...
topConstraint = make.top.equalTo(self.view.snp.bottom)
topConstraint.uninstall()
稍后删除顶部约束:

var topConstraint: Constraint? = nil
...
topConstraint = make.top.equalTo(self.view.snp.bottom)
topConstraint.uninstall()
然后使用另一个块创建新约束

directionList.snp.makeConstraints{ (make) -> Void in
   make.top.equalTo(self.topDarkBlue.snp.bottom)
}
声明UpdateConstraint仅用于更新现有约束的常量

如果仅更新 约束您可以使用snp.updateConstraints方法代替 snp.makeConstraints

您没有更新常量;您正在尝试将约束指定给新的定位点

我认为您应该做的是参考顶部约束:

var topConstraint: Constraint? = nil
...
topConstraint = make.top.equalTo(self.view.snp.bottom)
topConstraint.uninstall()
稍后删除顶部约束:

var topConstraint: Constraint? = nil
...
topConstraint = make.top.equalTo(self.view.snp.bottom)
topConstraint.uninstall()
然后使用另一个块创建新约束

directionList.snp.makeConstraints{ (make) -> Void in
   make.top.equalTo(self.topDarkBlue.snp.bottom)
}

你说的常数是什么意思?我在
UIView.animate
中使用updateConstraint,因此我需要将其保留为updateConstraint.NSLayoutConstraint的.constant属性。我不明白为什么不能对UIView.animate使用makeConstraints;虽然我不清楚是否需要调用makeConstraints调用layoutifneed。如果不是,请先调用make constraints,然后将self.view.layoutifneedd放入动画块中,以触发自动布局重新计算和帧更改。仅此常量是什么意思?我在
UIView.animate
中使用updateConstraint,因此我需要将其保留为updateConstraint.NSLayoutConstraint的.constant属性。我不明白为什么不能对UIView.animate使用makeConstraints;虽然我不清楚是否需要调用makeConstraints调用layoutifneed。如果不需要,请先调用“生成约束”,然后将self.view.layoutifneedd放入动画块中,以触发自动布局重新计算和帧更改。