如何让动画CAEmitterLayer /细胞的发射器的位置? [英] how to get the emitter position of an animated CAEmitterLayer/Cell?
问题描述
我有一个动画CAEmitterLayer与CAEmitterCell和动画与
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"];
我的贝塞尔路径是封闭的,形成了一个8出四点位置。
我timerFunction我试图让CAEmitterLayer每一秒的位置。对于我使用
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;
}
在发射器类和
CGPoint emitterPosition = [self.ParticleEmitterView getEmitterPosition];
NSLog(@"%f / %f", emitterPosition.y, emitterPosition.y);
从定时器功能。
但是,当动画运行控制台吐出来一样positio每次调用allthough发射器是运行在屏幕上。
But when the animation is running the console spits out the same positio every call allthough the emitter is running over the screen.
这是为什么,我怎么能拿一个动画CAEmitterLayer /细胞的发射器的位置?
why is that and how could I get the emitter position of an animated CAEmitterLayer/Cell?
推荐答案
您是否尝试过查询的 CAEmitterLayer
presentationLayer
财产,并要求所产生的的CALayer
为它的位置?在presentation层应该给你访问层的性能,因为它们出现在动画过程中在屏幕上,而发射器层会给你的属性,因为他们将在所有当前动画的结尾。
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.
这是由于<一个固有的模型 - 视图分离href=\"https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/CoreAnimationArchitecture.html#//apple_ref/doc/uid/TP40006655-SW1\"相对=nofollow>核心动画的渲染架构。
这篇关于如何让动画CAEmitterLayer /细胞的发射器的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!