title: (Swift 3) - How to include animations in custom UIView
body: <p>I have a <code>UIView</code> subclass called <code>View</code>, in which I want a "ripple" to move outwards from wherever the user double clicks (as well as preforming other drawing functions). Here is the relevant part of my <code>draw</code> method, at present:</p>
  
  <pre><code>override func draw(_ rect: CGRect) {
      for r in ripples {
          r.paint()
      }
  }
  </code></pre>
  
  <p>This is how <code>r.paint()</code> is implemented, in class <code>Ripple</code>:</p>
  
  <pre><code>func paint() {
      let c = UIColor(white: CGFloat(1.0 - (Float(iter))/100), alpha: CGFloat(1))
      print(iter, " - ",Float(iter)/100)
      c.setFill()
      view.fillCircle(center: CGPoint(x:x,y:y), radius: CGFloat(iter))
  }
  </code></pre>
  
  <p><code>iter</code> is supposed to be incremented every 0.1 seconds by a <code>Timer</code> which is started in the constructor of <code>Ripple</code>:</p>
  
  <pre><code>Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true, block: move)
  </code></pre>
  
  <p><code>move</code> is implemented as follows:</p>
  
  <pre><code>func move(_ timer: Timer) {
      while (tier&lt;100) {
          iter += 1
          DispatchQueue.main.async {
              self.view.setNeedsDisplay()
          }
      }
      timer.invalidate()
  }
  </code></pre>
  
  <p>What is supposed to happen is that every 0.1 seconds when the timer fires, it will increment <code>iter</code> and tell the <code>View</code> to repaint, which it will then do using the <code>Ripple.paint()</code> method, which uses <code>iter</code> to determine the color and radius of the circle.</p>
  
  <p>However, as revealed using <code>print</code> statements, what happens instead is that the <code>Timer</code> fires all 100 times before the redraw actually takes place. I have tried dealing with this by replacing <code>DispatchQueue.main.async</code> with <code>DispatchQueue.main.sync</code>, but this just made the app hang. What am I doing wrong? If this is just not the right way to approach the problem, how can I get a smooth ripple animation (which involves a circle which grows while changing colors) to take place while the app can still preform other functions such as spawning more ripples? (This means that multiple ripples need to be able to work at once.)</p>