title: Aligning four CAEmitterLayer() on each side of view, pointing inward
body: <p>I'm working on adding 4 <code>CAEmitterLayers</code> to a subview. Each <code>CAEmitterLayer</code> is a line, and will be positioned on each side. Rotation will be controlled via <code>CGAffineTransform</code></p>
  <p><strong>My problem:</strong></p>
  <p>I can't get the .Left and .Right emitterPosition to properly line up with the left and right side of the view</p>
  <p><strong>Here's my progress:</strong></p>
  <pre><code>override func awakeFromNib() {
      super.awakeFromNib()
      self.layer.cornerRadius = GlobalConstants.smallCornerRadius
      createParticles(direction: .Up)
      createParticles(direction: .Down)
      createParticles(direction: .Left)
      createParticles(direction: .Right)
  }
  
  enum EmitTo {
      case Up
      case Down
      case Left
      case Right
  }
  
  func createParticles(direction: EmitTo) {
      self.layoutSubviews()
      let particleEmitter = CAEmitterLayer()
      particleEmitter.position = CGPoint(x: self.bounds.midX, y: self.bounds.midY)
      particleEmitter.bounds = CGRect(x: 0, y: 0, width: self.bounds.size.width, height: self.bounds.size.height)
      
      
      if direction == .Up {
          particleEmitter.setAffineTransform(CGAffineTransform(rotationAngle: 0))
      } else if (direction == .Down) {
          particleEmitter.setAffineTransform(CGAffineTransform(rotationAngle: .pi))
      } else if (direction == .Left) {
          particleEmitter.setAffineTransform(CGAffineTransform(rotationAngle: .pi / 2))
      } else if (direction == .Right) {
          particleEmitter.setAffineTransform(CGAffineTransform(rotationAngle: -.pi / 2))
      }
      
      if direction == .Up || direction == .Down {
          particleEmitter.emitterPosition = CGPoint(x: self.frame.width / 2, y: 0)
      }
      if direction == .Left {
          particleEmitter.emitterPosition = CGPoint(x: self.frame.height / 2, y: self.frame.height)
      }
      if direction == .Right {
          particleEmitter.emitterPosition = CGPoint(x: self.frame.height / 2, y: -50)
      }
      
      
      particleEmitter.emitterSize = self.bounds.size
      particleEmitter.emitterShape = CAEmitterLayerEmitterShape.line
      particleEmitter.zPosition = 1
      
      let triangle = makeEmitterCell(direction: direction)
      particleEmitter.emitterCells = [triangle]
  
      self.layer.addSublayer(particleEmitter)
  }
  
  func makeEmitterCell(direction: EmitTo) -&gt; CAEmitterCell {
      let cell = CAEmitterCell()
      cell.birthRate = 25
      cell.lifetime = 3
      cell.lifetimeRange = 0
      cell.velocity = 10
      cell.velocityRange = 5
      cell.emissionLongitude = .pi
      
      cell.spin = 2
      cell.spinRange = 3
      cell.scale = 0.4
      cell.scaleRange = 0.6
      cell.scaleSpeed = -0.10
  
      cell.contents = UIImage(named: &quot;greenTriangle&quot;)?.cgImage
      return cell
  }
  </code></pre>
  <p><strong>What's happening:</strong></p>
  <p><a href="https://i.stack.imgur.com/0r8QU.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0r8QU.gif" alt="gif animation of particle system" /></a></p>
  <p><strong>My question</strong></p>
  <p>How can I get the <code>.Left</code> and <code>.Right</code> <code>CAEmitterLayer</code> to properly align with the left side and right side of the gray view?</p>
  <p><strong>Green Triangle Image:</strong></p>
  <p><a href="https://i.stack.imgur.com/XhIEK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XhIEK.png" alt="Green Triangle Image" /></a></p>