Chapter 10: Layer Animations fillMode

Hi there,

I’ve been going through this fantastic book on animations you have here and I’m having a blast doing so. I’ve come up on my first problem now though. In this chapter, there is an explanation that my animation for the username textfield will do the following:

it appears in the center of the screen, as it was designed in Interface Builder, and starts animating 0.3 seconds later. What gives?

However, I don’t see this happen at all. My animation starts off screen, waits 0.3 seconds, animates on screen and then remains there. Has something changed in Swift or the libraries, am I misunderstanding something, or? I’m unsure about why I’m going and changing the fillMode of the CABasicAnimation if it has no obvious effect.

My code:

override func viewWillAppear(_ animated: Bool) {
    let flyRight = CABasicAnimation(keyPath: "position.x")
    flyRight.fromValue = -view.bounds.size.width/2
    flyRight.toValue = view.bounds.size.width/2
    flyRight.duration = 0.5
    heading.layer.add(flyRight, forKey: nil)
    flyRight.beginTime = CACurrentMediaTime() + 0.3
    flyRight.fillMode = .both
    username.layer.add(flyRight, forKey: nil)
    flyRight.beginTime = CACurrentMediaTime() + 0.4
    flyRight.fillMode = .both
    password.layer.add(flyRight, forKey: nil)

Any help would be greatly appreciated!

@ev350 Do you still have issues with this?

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