【问题标题】:CAEmitterLayer negative beginTime possible?CAEmitterLayer 负 beginTime 可能吗?
【发布时间】:2012-08-21 12:30:40
【问题描述】:

我试图让CAEmitterLayers 和CAEmitterCells 从他们父母的持续时间中间的某个地方开始他们的动画。这可能吗?我尝试使用 beginTimetimeOffset 属性,但似乎无法正常工作。

为后代添加了一些代码:(假设我希望发射器在第 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,所以我设置单元格来做一个从屏幕顶部开始的“下落”动画。在开始渲染期间,我不想在“还没有下雨”的状态下开始。我想从屏幕已经被雨覆盖的地方开始。

【问题讨论】:

  • 能否提供一些代码,尤其是设置偏移量和开始时间的部分?
  • 我编辑了我的帖子以包含我的代码的基本结构。这是非常基本的设置。

标签: ios core-animation caemitterlayer


【解决方案1】:

beginTime 与现在无关。您需要获取相对于当前图层时间空间的当前时间,可以使用CACurrentMediaTime() 函数获取。所以在你的情况下,你会做这样的事情:

emitter.beginTime = CACurrentMediaTime() + 5.f;

【讨论】:

  • 老实说,我的 superLayer 是 AVSynchronizedLayer,所以我的计时是 AVPlayerLayer,而不是 CACurrentMediaTime()。但是,我确实用原始的UIView.layer 尝试了你的方法,但它的行为仍然不像我期望的那样。我开始认为发射器只处理向前运行的时序,而不是向后运行。
  • 哦,好吧,我想我解释错了。我不希望发射器在 5 秒后启动。我希望发射器比父时间早 5 秒运行。我编辑了问题以包含我想要做的示例。
  • @erurainon:如果我正确地理解了你的问题,你想要一个负偏移量,这确实是不可能的,原因很明显。 :) 但是,你不能只抵消父母吗?
  • 我也试过了,但没有效果。从理论上讲,一个积极的timeOffset 应该是做我所期望的,但似乎不是这样......
  • @erurainon:我想我不明白为什么你不能将发射器的 beginTime 设置为 5 秒后。也许我只是没有得到你想要做的事情。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-12
  • 1970-01-01
  • 2013-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多