Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Both ways seem to work, are there any differences in performance?
那么这真的取决于你想做什么。您可以从中调用它,init但只有在实例化类时才会调用代码。如果你把它放进去,layoutSubviews你可以通过重绘视图来多次调用代码。
init
layoutSubviews
因此,如果您需要根据事物的变化来更新约束,使用它可能是有利的,layoutSubviews但是如果您不需要修改约束,我会亲自创建一个名为的新方法setConstraints,该方法将包含所有约束并从init
setConstraints