[英]Correct method to setup iOS constriants
I just started using constraints in iOS. 我刚刚开始在iOS中使用约束。 I feel fairly comfortable with them, but now I'm wondering what's the proper way to create them.
我对它们很满意,但是现在我想知道创建它们的正确方法是什么。 I remember reading to create the constraints in a view's
updateConstraints
method. 我记得阅读过在视图的
updateConstraints
方法中创建约束的信息。 But I see that doing so could lead to adding multiple copies of the same constraints. 但是我看到这样做可能导致添加相同约束的多个副本。 Is this true, or will an exact duplicate constraint not be added?
这是真的,还是不添加确切的重复约束?
Should my constraints be added in the init and just updated in the updateConstraints
or is it okay to add and update the constraints in the updateConstraints
method? 应该将我的约束添加到init并在
updateConstraints
更新,还是可以在updateConstraints
方法中添加和更新约束?
根据Dave的评论,答案是在init
创建初始约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.