CAEmitterLayer,最终,在添加EmitterCells时有延迟

问题描述 投票:1回答:2

[我们遇到的一个非常奇怪的问题(下面的gif图片,]

  1. 我们提供了一个视图控制器,它的TeamBadgeView,这是一个按CAEmitterCells发出表情符号的按钮
  2. 点击此按钮可使用户在屏幕上发送垃圾表情符号垃圾邮件
  3. 关闭呈现的视图控制器,然后重新呈现视图控制器,现在有了延迟。我展示/关闭视图控制器的次数越多,CAEmitterCell就会变得越来越无响应
  4. 确认这不是泄漏问题,视图控制器和按钮已正确释放
  5. 我已经尝试过移动CAEmitterLayerCAEmitterCell,在按钮中保持引用,并在本地声明,但是类似的问题
  6. 也许是最奇怪的,如果我根本不按按钮,而只是多次显示/关闭视图控制器,然后按按钮,则会有延迟。没有延迟的唯一时间是第一次显示View Controller时按下按钮
  7. 每次我向按钮发送垃圾邮件时,我均已确认按钮的action被正确触发。只是发射器单元几秒钟没有渲染。而且有些发射器单元根本不渲染
  8. 已经到了令人难以置信的地步,有人对这可能有什么想法或线索吗?

ViewController的第一个演示:enter image description here

在ViewController的第5次演示后(以相同的速率按下按钮):

enter image description here

ViewController代码:

let teamBadgeView = TeamBadgeView.fromNib()
teamBadgeView.configure()

按钮代码:

class TeamBadgeView: UIView {
    let emitter = CAEmitterLayer()
    let fireSize = CGSize(width: 16, height: 18)
    let fireScale: CGFloat = 0.8

    func configure() {
        emitter.seed = UInt32(CACurrentMediaTime())
        emitter.emitterPosition = CGPoint(x: bounds.midX, y: 0)
        emitter.emitterShape = CAEmitterLayerEmitterShape.line
        emitter.emitterSize = fireSize
        emitter.renderMode = CAEmitterLayerRenderMode.additive
        layer.addSublayer(emitter)
    }

    @IBAction func tapAction(_ sender: Any) {
        emitFire()
    }

    private func emitFire() {
        let cell = CAEmitterCell()
        let beginTime = CACurrentMediaTime()
        cell.birthRate = 1
        cell.beginTime = beginTime
        cell.duration = 1
        cell.lifetime = 1
        cell.velocity = 250
        cell.velocityRange = 50
        cell.yAcceleration = 100
        cell.alphaSpeed = -1.5
        cell.scale = fireScale
        cell.emissionRange = .pi/8
        cell.contents = NSAttributedString(string: "🔥").toImage(size: fireSize)?.cgImage

        emitter.emitterCells = [cell]
    }
}

[我们一直看到的一个非常奇怪的问题(下面的gif图像),我们提供了一个带有TeamBadgeView的View Controller,它是一个在CAEmitterCells发出emoji表情的按钮。点击此按钮可使...

ios uikit core-animation caemitterlayer caemittercell
2个回答
1
投票
而不是每次都设置emitterCells数组:

0
投票
感谢@TylerTheCompiler,我们得以弄清楚了,真是really脚。
© www.soinside.com 2019 - 2024. All rights reserved.