如何以编程方式禁用约束? [英] How to disable a constraint programmatically?

查看:94
本文介绍了如何以编程方式禁用约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式禁用约束?

How to disable a constraint programmatically?

我有两个约束,一个约束的优先级取决于另一个约束。据我所知,约束优先级在安装时无法以编程方式更改(这会引发错误),所以想法是,当X发生时,约束A禁用,约束B启用,当Y发生A是启用,而B禁用

I have two constraints, that the priority of one depends for the other. As far as I know the constraints priority can’t change programmatically when they are installed (it throw me an error), So the idea is, when X occurs the constraint A is disable and the constraint B is enable, and when Y occur A is enable and B disable

IBOutlet weak var constraint_A
IBOutlet weak var constraint_B

... 

func configureViews() {
   if x {
        constraint_A.disable = true
        constraint_B.disable = false
   }  else {
        constraint_A.disable = false
        constraint_B.disable = true
   }
}
...


推荐答案

约束有一个名为 active 的布尔属性,因此如果要禁用约束您可以轻松地调用它:

The constraints have a boolean property called active so if you want to disable a constraint you can easily call it:

constraint_A.active = false

这篇关于如何以编程方式禁用约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆