CABasicAnimation

Discussion in 'Public Game Developers Forum' started by Heber, Jul 2, 2009.

  1. Heber

    Heber Member

    Jun 30, 2009
    5
    0
    0
    Lindon, Utah
    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..?)
     
  2. NickFalk

    NickFalk Well-Known Member

    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. :)
     
  3. Heber

    Heber Member

    Jun 30, 2009
    5
    0
    0
    Lindon, Utah
    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!
     
  4. drunknbass

    drunknbass Well-Known Member

    Nov 8, 2008
    128
    0
    0
    please read up on implicit vs explicit animations.
    http://developer.apple.com/documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/AnimatingLayers.html
     

Share This Page