旋转设备时,有没有办法让CAEmitter以UIView为中心(使用Autolayout)?
我将我的发射器添加到viewDidLoad,如下所示:
// setup emitter
let emitter = CAEmitterLayer()
emitter.frame = self.view.bounds
emitter.renderMode = kCAEmitterLayerAdditive
emitter.emitterPosition = self.view.center
self.view.layer.insertSublayer(emitter, atIndex: 1)
// setup cells
let cell = CAEmitterCell()
cell.contents = UIImage(named: "particle")?.CGImage
cell.birthRate = 1500
cell.lifetime = 5.0
cell.color = UIColor(red: 1.0, green: 0.5, blue: 0.1, alpha: 1).CGColor
cell.alphaSpeed = -0.4
cell.velocity = 50
cell.velocityRange = 250
cell.emissionRange = CGFloat(M_PI) * 2.0
//add cells to the emitter
emitter.emitterCells = [cell]
我试图删除它并重新添加它但它没有居中....
答案 0 :(得分:1)
override func viewDidLayoutSubviews() {
emitter.emitterPosition = self.view.center
}