Roman Minenok
Roman Minenok

Reputation: 9368

UIViewAnimationOptionBeginFromCurrentState equivalent when working with CALayer

What is the equivalent of UIViewAnimationOptionBeginFromCurrentState flag when adding CABasicAnimation directly to the layer? I'd want to override my current animation when I'm adding another one for the same key and make it begin animation from the current state.

E.g, I am adding animations to my layer with the following code.

CABasicAnimation *moveAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
    moveAnimation.fromValue = [NSNumber numberWithInt:layer.position.y];
    moveAnimation.toValue = [NSNumber numberWithInt:0];
    moveAnimation.duration = BUBBLE_DEFAULT_ANIMATION_DURATION;
[layer addAnimation:moveAnimation forKey:key]; 

Any help would be totally appreciated.

Upvotes: 1

Views: 944

Answers (1)

Robin Summerhill
Robin Summerhill

Reputation: 13675

Set fromValue to nil to start from the current presentation layer value.

From the documentation for CABasicAnimation:

  • toValue is non-nil. Interpolates between the current value of keyPath in the target layer’s presentation layer and toValue.

Upvotes: 6

Related Questions