SnapKit使用snp_updateConstraints更新CenterX失败

我在使用SnapKit进行AutoLayout布局的时候,首先先对一个LineView进行布局

        let lineView = UIView()
        lineView.tag = 99
        lineView.backgroundColor = UIColor(hexString: "f5fc9b")
        self.channelTitleScrollView.addSubview(lineView)
        lineView.snp_makeConstraints { (make) in
            make.height.equalTo(2)
            make.bottom.equalTo(tempBtn)
            make.centerX.equalTo(tempBtn)
            make.width.equalTo(tempBtn)
        }

当我点击了另外一个按钮的时候,需要将这个LineView移动到相应的按钮下面,我使用的是

            lineView.snp_updateConstraints(closure: { (make) in
                make.centerX.equalTo(selectBtn)
                make.width.equalTo(selectBtn)
            })

但是这段代码执行以后,AutoLayout错误
经过注释后发现,width可以实现,但是CenterX冲突了,updateConstraints不能更新CenterX么?

阅读 4.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进