how to get the emitter position of an animated CAEmitterLayer/Cell?

我只是一个虾纸丫 提交于 2020-01-03 03:41:07

问题


I have a animated CAEmitterLayer with CAEmitterCell and the animation runs well with

 fireEmitter = (CAEmitterLayer*)self.layer; 
    fireEmitter.emitterPosition = CGPointMake(50, 50);
    fireEmitter.emitterSize = CGSizeMake(10, 10);

    CAEmitterCell* fire = [CAEmitterCell emitterCell];
    ...
    [fire setName:@"fire"];

CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"emitterPosition"];
    anim.path = theBezierPath.CGPath;
    anim.calculationMode = kCAAnimationCubicPaced;
    anim.repeatCount = HUGE_VALF;
    anim.duration = 12.0;
    [self.layer addAnimation:anim forKey:@"fire"];

my bezier path is closed and forms a "8" out of four position points. with my timerFunction I try to get the position of the CAEmitterLayer every second. for that I use

-(CGPoint)getEmitterPosition
{
    return fireEmitter.emitterPosition;
}

in the emitter class and

CGPoint emitterPosition = [self.ParticleEmitterView getEmitterPosition];
NSLog(@"%f / %f", emitterPosition.y, emitterPosition.y);

from the timer function.

But when the animation is running the console spits out the same positio every call allthough the emitter is running over the screen.

why is that and how could I get the emitter position of an animated CAEmitterLayer/Cell?


回答1:


Have you tried querying the CAEmitterLayer's presentationLayer property and asking the resulting CALayer for its position? The presentation layer should give you access to the properties of the layer as they appear on the screen during the animation, while the emitter layer will give you the properties as they will be at the end of all current animations.

This is due to the model-view separation inherent in Core Animation's rendering architecture.



来源:https://stackoverflow.com/questions/10885480/how-to-get-the-emitter-position-of-an-animated-caemitterlayer-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!