I’m a little confused about the animation at the beginning of the chapter that animates the highlight view.
I think my confusion is mostly about how the animations: ()-Void
closure works.
I get how it works in general, for any animatable property. The property has some initial/current value (let’s say 0), and in the block you update the property to a new value (let’s say 10). When the animation is started, the property’s value will be incremented from its current value to the new value (so, 1, 2, 3, … 8, 9, 10) and as it does so, the UI is redrawn in each of those states (I realize this is an over-simplification), and the view animates …
I also understand the need for layoutIfNeeded()
in the case of constraints, for all of the reasons laid out in the book.
What I’m confused about is WHERE the layoutIfNeeded
call happens … it seems like it would need to be called each time the system increments the current constraint value (from 1 to 2, from 2, to 3, etc). But it’s only called once (when the animations:
block runs). How does it know “not to wait” (to use phrasing from the book) as it increments the constraint value from 0 to 10?