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’m 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’t understand is why the constraints worked fine and didn’t need that BEFORE you put the animation block in.

Hi! Totally reasonable question. Essentially, even though we’re activating the constraints, Auto Layout isn’t updating the layout to use them until showItem is finished executing.

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

Hope that helps!