问题描述
我已通过互联网寻找此问题,但找不到与我的问题相关的任何解决方案。
这是我目前编写的代码。
创建 CAEmitterLayer 如下:
func createParticles() {
let particleEmitter = CAEmitterLayer()
particleEmitter.emitterPosition = CGPoint(x: self.confettIoUterView.frame.width / 2,y: 0)
particleEmitter.emitterShape = .line
particleEmitter.emitterSize = CGSize(width: self.confettIoUterView.frame.size.width,height: 1)
let red = makeEmitterCell(color: .celebration_color_01) // custom color
let green = makeEmitterCell(color: .celebration_color_02) // custom color
let blue = makeEmitterCell(color: .celebration_color_03) // custom color
particleEmitter.emitterCells = [red,green,blue]
self.confettIoUterView.layer.addSublayer(particleEmitter)
}
按如下方式创建每个 CAEmitterCell:
func makeEmitterCell(color: UIColor) -> CAEmitterCell {
let cell = CAEmitterCell()
cell.color = color.cgColor // this thing is not working I think
cell.birthRate = 30
cell.lifetime = 1.0
cell.lifetimeRange = 2.0
cell.veLocity = 200
cell.veLocityRange = 100
cell.emissionLongitude = CGFloat.pi
cell.emissionRange = CGFloat.pi / 4
cell.spin = 2
cell.spinRange = 5
cell.scale = 0.2
cell.scaleRange = 0.1
cell.contents = UIImage(named: "rate-us")?.cgImage
return cell
}
我使用的图片来自此链接:https://icons8.com/icon/10276/diamonds
我在这里做错了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)