Perhaps emitterPosition.x
is not a valid key path for animation. Try using emitterPosition
instead (and so you'll have to provide CGPoint values wrapped up in an NSValue).
I just tried this on my own machine and it works fine:
CABasicAnimation* ba = [CABasicAnimation animationWithKeyPath:@"emitterPosition"];
ba.fromValue = [NSValue valueWithCGPoint:CGPointMake(30,100)];
ba.toValue = [NSValue valueWithCGPoint:CGPointMake(200,100)];
ba.duration = 6;
ba.autoreverses = YES;
ba.repeatCount = HUGE_VALF;
[emit addAnimation:ba forKey:nil];
Other things to think about:
You can typically use nil as the key in
addAnimation:forKey:
, unless you're going to need to find this animation later (e.g. to remove it or override it in some way). The key path is the important thing.Setting
removedOnCompletion
to NO is almost always wrong and is typically the last refuge of a scoundrel (i.e. due to not understanding how animation works).If, as you say, setting
_emitterLayer.emitterPosition = newEmitterPosition
inside the completion block does animate, then when why are you using CABasicAnimation at all? Why not just call UIViewanimate...
and set the emitterPosition in the animations block? If that works, it will kill two birds with one stone, moving the position and animating it too.