title: Animate CAShapelayer content when new item is added
body: <p>I need to render moving audio waveform like iOS voice memo app. Here I maintain waveform:[Int] rms amplitude of waves.
  Now when new waves come add it in waveform[Int] and I add new <code>UIBezierPath</code> line at right of <code>CAShapeLayer</code> and translate whole <code>CAShapeLayer</code> by 5 points.</p>
  <p>But translation animation is not so smooth. Could you please suggest any better approach for it?</p>
  <p>My current implementation:</p>
  <pre class="lang-swift prettyprint-override"><code>override func draw(_ rect: CGRect) {
  
      shiftWaveform()
      let path: UIBezierPath!
      
      if let ppath = caLayer.path {
          path = UIBezierPath(cgPath: ppath)
      } else {
          path = UIBezierPath()
      }
  
      guard var wave = waveforms.last else { return }
      
      if (Int(wave) &lt;= 2) {
          wave = 2
      }
      
      count += 1
      let startX = Int(self.bounds.width) + 5*count
      let startY = Int(self.bounds.origin.y) + Int(self.bounds.height)/2
      
      path.move(to: CGPoint(x: startX, y: startY + min(wave, Int(bounds.height/2))))
      path.addLine(to: CGPoint(x: startX, y: startY - min(wave, Int(bounds.height/2))))
      caLayer.path = path.cgPath
  }
  </code></pre>