激活在故事板中卸载的约束

Activating a constraint which was uninstalled in the storyboard

我有一个包含一些约束的视图。其中一些已关闭“已安装”复选框。我正在尝试根据我的应用程序的状态激活和停用特定约束。

问题是,当已安装的复选框关闭时,我无法激活约束,也无法停用已安装的约束。 我需要提及的是,我对 size 类 属性中的约束使用了强引用。我还尝试了一种在 activating/deactivating 约束之后调用 setNeedsUpdateConstraints 和 updateConstraintsIfNeeded、setNeedsLayoutlayoutIfNeeded 的方法。

我找不到任何关于此行为的文档,为什么会这样?

OutLet 作为特定约束,例如:

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraint;)
//For Installing

[self.view addConstraint: constraint]

//For Uninstalling 

[self.view removeConstraint: constraint]

确保将代码放在正确的位置

override func viewDidLayoutSubviews() {
// write your code here 
}