更新约束

Update constrains

请帮我解决问题。 我有创建复选框的功能。在这个函数中,我每次增加 UIVIew 的高度:

self.myView.addSubview(MyCheckbox)
myFrame.origin.y += myFrame.size.height. // This is the Y position of new checkbox. I.m creating a frame with checkbox and it's title inside. It's height depends on checkbox picture height.
self.myView.frame = CGRectMake(self.myView.frame.origin.x, self.myView.frame.origin.y, self.myView.frame.size.width, myFrame.origin.y) // And this is the updated frame with new Height.

在那种情况下,我 myView 内部带有复选框并具有新的高度(注意:在界面生成器中默认高度为 1.0) 但是位于 myView 下面的其他 UIView 在他的位置上静止不动。 如何更新 myView 的高度限制?或者在我创建复选框时自动调整它的大小?

感谢大家!

要处理此问题,请将界面构建器中的约束拖到 class 并制作一个 IBOutlet。

@IBOutlet weak var heightConstraint: NSLayoutConstraint!

然后像这样设置constraint.constant:

heightConstraint.constant = 50