-->

如何让动画CAEmitterLayer /电池的发射位置?(how to get the emitt

2019-09-17 17:53发布

我有一个动画CAEmitterLayer与CAEmitterCell和动画与运行良好

 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"];

我的贝塞尔曲线是封闭的,并形成一个“8”出四个位置点。 我timerFunction我试图让CAEmitterLayer每秒的位置。 为此,我使用

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

在发射器和类

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

从定时器功能。

但是,当动画运行控制台吐出每一个电话allthough发射器运行在屏幕上的相同positio。

这是为什么,我怎么能拿动画CAEmitterLayer /电池的发射位置?

Answer 1:

您是否尝试过查询CAEmitterLayerpresentationLayer物业,并要求所产生CALayer对自己的立场? 表示层应该给你访问层的特性,其在动画中出现在屏幕上,而发射层会给你的特性,其将在所有当前动画的结尾。

这是由于所固有的模型-视图分离核心动画的渲染架构 。



文章来源: how to get the emitter position of an animated CAEmitterLayer/Cell?