关于Layout Constraint的动态update方式

最好的方式就是,change发生是及时地改变。相应的constraint、


Batching Changes

It is almost always cleaner and easier to update a constraint immediately after the affecting change has occurred. Deferring these changes to a later method makes the code more complex and harder to understand.

However, there are times when you may want to batch changes for performance reasons. This should only be done when changing the constraints in place is too slow, or when a view is making a number of redundant changes.

To batch a change, instead of making the change directly, call thesetNeedsUpdateConstraintsmethod on the view holding the constraint. Then, override the view’supdateConstraintsmethod to modify the affected constraints.、

只有在性能调优的时候。才需要使用

setNeedsUpdateConstraints  和 updateConstraints

猜你喜欢

转载自blog.csdn.net/dayuqi/article/details/53965277