1
votes

I'm reasonably new to iOS/Obj-C/Cocoa development (day 5!), so I'm sure I'm probably missing something basic here, but anyway…

Say I have an animation (a CABasicAnimation) to change the position.y property of my CALayer. I set the duration to 10 seconds, and start the animation. 5 seconds later, due to user interaction, I want to change the destination position.y of the animation.

I have tried two approaches:

  1. Change the toValue of the in-flight animation

    This simply resulted in no change to the animation (though obviously it "jumped" to the actual position when it was over)

  2. Cancel the running animation (removeAnimationForKey:), and start a new one. The issue here is I have no way to get the current position.y from the running animation for the new animation.

I see (brief/vague) mention of "animation retargeting" in the Core Animation documentation for OS X, but no such mention in iOS.

Is this possible?

1
try to start the next animation with fromValue = [[layer presentationLayer] position].y; - Felix
@phix23 Thank you, perfect. I had read about the distinction between render/presentation/layer trees, but didn't know there was a way to access values in the presentation layer. - obeattie

1 Answers

0
votes

try to start the next animation with fromValue = [[layer presentationLayer] position].y;

(as answered in the comments above by @phix23)