旋转设备时保持 CAEmitter 居中

Keep CAEmitter centered when rotating device

有没有办法在旋转设备时让 CAEmitter 以 UIView 为中心(使用自动布局)?

我正在将我的发射器添加到 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]

我试过将其删除并重新添加,但它没有居中....

好的,知道了。对于遇到此问题的任何人...

 override func viewDidLayoutSubviews() {

      emitter.emitterPosition = self.view.center

     }