[我们遇到的一个非常奇怪的问题(下面的gif图片,]
TeamBadgeView
,这是一个按CAEmitterCells
发出表情符号的按钮CAEmitterCell
就会变得越来越无响应CAEmitterLayer
和CAEmitterCell
,在按钮中保持引用,并在本地声明,但是类似的问题action
被正确触发。只是发射器单元几秒钟没有渲染。而且有些发射器单元根本不渲染已经到了令人难以置信的地步,有人对这可能有什么想法或线索吗?
在ViewController的第5次演示后(以相同的速率按下按钮):
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表情的按钮。点击此按钮可使...
emitterCells
数组: