Chapter 8 - Animations vs. real content

I cannot understand the section “Animations vs. real content” in Ch. 8. I mean, all code works fine with fillMode = kCAFillModeBoth and default isRemovedOnCompletion = true, 'cause we already start with textview on the center of the superview.

This is not true:

To start, remember you’re setting the text field to be positioned offscreen in viewWillAppear(_:):

'Cause of this:

Scroll to viewWillAppear() and remove the following line: username.center.x -= view.bounds.width

And I can’t understand this:

You removed the line that sets fromValue some time ago, but the code above updates the main layer’s position; this causes the animation to start from the center of the screen. To fix this, add the following line just after you initialize flyRight and set its toValue:

flyRight.fromValue = -view.bounds.size.width/2

We are talking of the toValue but the code present fromValue

In the debugging section, you added this to ViewWillAppear:

username.layer.position.x -= view.bounds.width
password.layer.position.x -= view.bounds.width

which makes username once again offscreen.

This should be read as
“To fix this, find the spot in your code where you have initialized flyRight and have set its toValue, and after those two add this line to set its fromValue:”

What you want to end up with, then, is the text fields set to their final resting place:

 username.layer.position.x = view.bounds.size.width/2

and the animation set to start off screen.

flyRight.fromValue = -view.bounds.size.width/2

Hi @sgerrard! Thanks to helping me find out what I cannot see.

What I’ve quoted is exactly the lines of code that will explain the views are out of screen… but I cannot find this lines on my book version. I’ve the PDF digital version.

I start reading from chapter 8 using the chapter 8 starter project, not the project built up from the beginning (chapter 1). Anyway If I only follow chapter 8 It seems to me that some information is missing… Where do I see wrong?

I just looked in the latest version, version 5, and it looks like they removed the part about debugging the animation. If you are in version 5, that would explain why you can’t find it.

Still, it’s the final result that matters: objects set at their final location, animation set to start offscreen.

Gotcha!

Thanks @sgerrard again for your support.

This topic was automatically closed after 166 days. New replies are no longer allowed.