title: iOS: UITableView acceleration slows down when doing animations in willDisplayCell
body: <p><strong>LATEST EDIT:</strong>
  After some more experimentation I'm convinced that I'm running into a touch handling issue.<br>
  I created a custom cell with a subview that fills half the width of the content view. I'm animating that subview instead of the content view.</p>
  
  <p><a href="https://i.stack.imgur.com/EOPLb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EOPLb.png" alt="Cell with Half view"></a></p>
  
  <p>Scrolling the tableview while touching the right side of the cell works normally.<br>
  Scrolling the tableview on the left side of the cell (where the animating view is) causes lag.</p>
  
  <p><strong>EDIT:</strong>
  In the end I'm trying to do an animation similar <a href="https://stackoverflow.com/questions/17764991/uicollectionview-animate-cells-as-they-scroll-in">to this one</a>.
  The accepted answer in that question has the same problem I'm asking about.
  The code below is the simplest one that reproduces the issue.</p>
  
  <p>Doing the animation in <code>dequeCellForIndexPath</code> instead of <code>willDisplayCell</code> makes no difference.</p>
  
  <p>When doing animations in <code>willDisplayCell</code>, table view scrolling animation slows down. When you try to scroll fast in the tableview, the scrolling loses acceleration.</p>
  
  <p>Some sample code that reproduces the issue:</p>
  
  <pre><code>class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
  
      @IBOutlet var tableView: UITableView!
  
      func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
  
          cell.contentView.layer.opacity = 0.0
  
          UIView.animateWithDuration(0.3) {
              cell.contentView.layer.opacity = 1.0
          }
      }
  
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          let cell = UITableViewCell()
  
          cell.textLabel?.text = "\(indexPath.row)"
  
          return cell
      }
  
  
      func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -&gt; CGFloat {
          return 300
      }
  
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return 5000
      }
  }
  </code></pre>
  
  <p>The problem gets worst when the cell's height is big. </p>
  
  <p>Is there anyway to avoid this, or some better function to do cell animations in?</p>
  
  <p>Related: <a href="https://www.raywenderlich.com/76024/swift-table-view-animations-tutorial-drop-cards" rel="nofollow noreferrer">Blogpost on doing animations like this</a></p>
  
  <p><strong>EDIT 2:</strong>
  GIFs illustrating the issue:</p>
  
  <p>In all 3 cases I'm scrolling as fast as I can on my phone.</p>
  
  <p>With an animation in willDisplayCell I reach row 60 </p>
  
  <p><a href="https://i.stack.imgur.com/a0gsv.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a0gsv.gif" alt="Using Animation"></a></p>
  
  <p>Without an animation I reach row 400+</p>
  
  <p><a href="https://i.stack.imgur.com/Xtm8N.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xtm8N.gif" alt="Normal Scrolling"></a></p>
  
  <p>With a random delay between 0 - 0.3 seconds in willDisplayCell, blocking the main queue, I reach row 120</p>
  
  <p><a href="https://i.stack.imgur.com/1MEEq.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1MEEq.gif" alt="Laggy Scrolling"></a></p>
  
  <p>I guess there's an issue with touch handling somewhere.</p>
  
  <p>Even <a href="https://github.com/morizotter/TouchVisualizer" rel="nofollow noreferrer">the library I use to visualize how fast I'm scrolling</a>, breaks when using animations in <code>willDisplayCell</code>.</p>