★ TouchArcade needs your help. Click here to support us on Patreon.

CABasicAnimation

07-01-2009, 06:42 PM
#1
Junior Member [Original Poster]
Joined: Jun 2009
Location: Lindon, Utah
Posts: 5
CABasicAnimation

I am using CABasicAnimations to animate CALayers. I animate a property (like "position") from it's current value to a new value. I add the animation to a CALayer, and the animation runs.

However, as soon as the animation ends, the position property jumps back to it's original value. I'd like it to retain the ending value from the animation. Is there something I'm missing here?

(I'm using a CABasicAnimation so that I can control the duration of the animation, so I may just need to use a different approach..?)

Heber Sheffield
Developer
Polished Play, LLC
07-02-2009, 01:48 AM
#2
Joined: Mar 2009
Location: Oslo, Norway
Posts: 731
Perhaps something like...
Code:
[CALayer setAnimationBeginsFromCurrentState:YES];
...is what you're looking for?

It's always easier for people to comment if you include some code-snippets by the way.
07-03-2009, 01:06 PM
#3
Junior Member [Original Poster]
Joined: Jun 2009
Location: Lindon, Utah
Posts: 5
Thank you for your response! I'm a first-time forum contributor, and it's exciting to see people helping each other

As to your suggestion, from what I can tell, setAnimationBeginsFromCurrentState is a method on UIView, not CALayer (though I did play around with it, and it does work as expected)

Here is a snippet of code
Code:
	CAKeyframeAnimation *slideAnimation = [CAKeyframeAnimation animation];
	slideAnimation.path = slidePath;
	slideAnimation.duration = SLIDE_PAPER_IN_DURATION;
	CGPathRelease(slidePath);
	[layerPaper addAnimation:slideAnimation forKey:@"position"];
In the above code, layerPaper starts in position 'A'.
The slidePath starts at position 'A' and ends at position 'B'.

The behavior I want is: when slideAnimation ends, layerPaper will remain in position 'B'.

However, what I am seeing is: when the animation ends, the layer jumps back to position 'A' (presumably because the animation was removed from the layer)

I try with a delegate to 'manually' set the layerPaper position to 'B' when the animation finishes, but sometimes get a flicker (of it jumping back to 'A', and then being set to 'B')

Any thoughts?
Thanks again!

Heber Sheffield
Developer
Polished Play, LLC
07-03-2009, 10:28 PM
#4
Joined: Nov 2008
Posts: 128
Quote:
Originally Posted by Heber View Post
Thank you for your response! I'm a first-time forum contributor, and it's exciting to see people helping each other

As to your suggestion, from what I can tell, setAnimationBeginsFromCurrentState is a method on UIView, not CALayer (though I did play around with it, and it does work as expected)

Here is a snippet of code
Code:
	CAKeyframeAnimation *slideAnimation = [CAKeyframeAnimation animation];
	slideAnimation.path = slidePath;
	slideAnimation.duration = SLIDE_PAPER_IN_DURATION;
	CGPathRelease(slidePath);
	[layerPaper addAnimation:slideAnimation forKey:@"position"];
In the above code, layerPaper starts in position 'A'.
The slidePath starts at position 'A' and ends at position 'B'.

The behavior I want is: when slideAnimation ends, layerPaper will remain in position 'B'.

However, what I am seeing is: when the animation ends, the layer jumps back to position 'A' (presumably because the animation was removed from the layer)

I try with a delegate to 'manually' set the layerPaper position to 'B' when the animation finishes, but sometimes get a flicker (of it jumping back to 'A', and then being set to 'B')

Any thoughts?
Thanks again!
please read up on implicit vs explicit animations.
http://developer.apple.com/documenta...ingLayers.html