我正在尝试让 CAEmitterLayer
和 CAEmitterCell
从它们父级持续时间中间的某个地方开始它们的动画。这可能吗?我尝试使用 beginTime
和 timeOffset
属性,但似乎无法正常工作。
为后代添加了一些代码:(假设我希望发射器在第 5 秒开始)
CAEmitterLayer *emitter = [CAEmitterLayer new];
// emitter.beginTime = -5.0f; // I tried this
// emitter.timeOffset = 5.0f; // I also tried this, with beginTime = 0.0, and with beginTime = AVCoreAnimationBeginTimeAtZero
/* set some other CAEmitterLayer properties */
CAEmitterCell *cell = [CAEmitterCell new];
// cell.beginTime = -5.0f; // Then I saw that CAEmitterCell implements CAMediaTiming protocol so I tried this
// cell.timeOffset = 5.0f; // and this
/* set some other CAEmitterCell properties */
emitter.emitterCells = @[cell];
[viewLayer addSubLayer:emitter];
但动画仍然从发射器生成粒子的地方开始。
再次编辑以解释我要做什么:
假设我有一个 CAEmitterLayer
可以为雨设置动画,所以我将单元格设置为执行从屏幕顶部开始的“下落”动画。在渲染开始期间,我不想以“尚未下雨”的状态开始。我想从屏幕已经被雨水覆盖的地方开始。
最佳答案
beginTime
与现在无关。您需要获取相对于当前图层时间空间的当前时间,您可以使用 CACurrentMediaTime()
函数获取该时间。所以在你的情况下,你会做这样的事情:
emitter.beginTime = CACurrentMediaTime() + 5.f;
关于ios - CAEmitterLayer 负 beginTime 可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12047402/