Beginning iOS Animations 路 Animating Dynamically Created Views | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/9051-beginning-ios-animations/lessons/4

Hi. I鈥檓 really confused. Please can you help?

At 03:10 you have the dynamically created view, forced by the constraints almost off the bottom centre of the screen.

I understand that.

However, when you add in the animation, the view starts from top left?!

Now, I know you fixed it with the layoutifneeded, but what I don鈥檛 understand is why the constraints worked fine and didn鈥檛 need that BEFORE you put the animation block in.

Hi! Totally reasonable question. Essentially, even though we鈥檙e activating the constraints, Auto Layout isn鈥檛 updating the layout to use them until showItem is finished executing.

Before the animation is added, that鈥檚 not a problem. But these animations take the layout that exists when they鈥檙e called as the starting state. So, before we fixed it, all of the constraints we made and then modified in the animation closure aren鈥檛 being evaluated by Auto Layout until the call to layoutIfNeeded in the animation closure.

Hope that helps!