Group Group Group Group Group Group Group Group Group

Chapter 8 Layer Animations

#1

The following code to move the header using layer animation works but I have a question regarding the code below. Why is the view.bounds.size.width divided by 2? I tried to used different numbers and it didn’t make a difference.

let flyRight = CABasicAnimation(keyPath: “position.x”)
flyRight.fromValue = -view.bounds.size.width/2
flyRight.toValue = view.bounds.size.width/2
flyRight.duration = 0.5

Thanks!

Jeff

#2

@jeffamine Thanks very much for your question, and my apologies for the delayed response.

In line 2: If you notice, the value is negative (-). This means that this distance is FROM the right border. So if I understand your code correction, it is moving at a position that is half-way FROM the right edge. This would be the starting point.

In line 3: The end point is the same value, but is in the opposite direction (i.e. it is at the right edge).

My guess is that your starting point is in the center, and you are moving to the right, at a speed that would take 1/2 a second to complete.

I hope this helps!

All the best!