SaldaVonSchwartz
SaldaVonSchwartz

Reputation: 3809

how come I replace a CALayer's position implicit animation and it still kicks in just before my own?

I'm doing something like this:

  CABasicAnimation* translateA = [CABasicAnimation animation];
  translateA.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  translateA.fillMode = kCAFillModeBoth;
  translateA.duration = 1;

  CALayer* nextLayer = <some layer...>
  [nextLayer addAnimation:translateA forKey:@"position.y"];
  newPos = nextLayer.position;
  newPos.y += someDelta;
  nextLayer.position = newPos;

And what happens is I see the layer almost "jump" to its final position and then my animation kicks in. My guess is the "almost jump" actually is the original implied animation for "position" (which is very short in duration). I also tried replacing for position instead of position.y and also tried replacing the whole actions dictionary in the layer (just to add this animation). But I always get the same result.

How would I go about it so that effectively I only see the layer translate for 1 sec.?

Upvotes: 1

Views: 239

Answers (1)

NachoSoto
NachoSoto

Reputation: 1743

Can you show more code? I was getting this problem when using custom properties in drawInContext:

I had this in my own layer:

+ (BOOL)needsDisplayForKey:(NSString *)key
{
    if ([key isEqualToString:@"progress"])
        return YES;
    else
        return [super needsDisplayForKey:key];
}

And when doing this:

[self.layer setValue:@1 forKey:@"progress"];

And then:

[self.layer addAnimation:animation forKey:@"progress"];

drawInContext: was being called with progress 1 before the animation kicked in. Turns out the problem was that I was synthesizing the property (progress) with @dynamic. Removing this actually solved my problem :-)

Upvotes: 1

Related Questions