Why calling setNeedsUpdateConstraints isn't needed for constraint changes or animations?

前端 未结 3 1349
半阙折子戏
半阙折子戏 2020-12-04 14:03

Readings:

From this answer:

This is what the accepted answer suggests to animate your view changes:

_addBannerDistanceFromBottomConstraint.         


        
3条回答
  •  再見小時候
    2020-12-04 14:27

    setNeedsUpdateConstraints will update the constraints that will be changed based on a change you have made. For example if your view has a neighboring view with which there a constraint of horizontal distance, and that neighbor view got removed, the constraint is invalid now. In this case you should remove that constraint and call setNeedsUpdateConstraints. It basically makes sure that all your constraints are valid. This will not redraw the view. You can read more about it here.
    setNeedsLayout on the other hand marks the view for redrawing and putting it inside animation block makes the drawing animated.

提交回复
热议问题