title: How to add tap gesture to UICollectionView , while maintaining cell selection?
body: <h1>Task</h1>
  
  <p>Add a single tap gesture to <code>UICollectionView</code>, do not get in the way of cell selection. </p>
  
  <p>I want some other taps on the no-cell part of the collectionView.</p>
  
  <h1>Code</h1>
  
  <p>Using XCode8, Swift 3.</p>
  
  <pre><code>override func viewDidLoad() {
      ...
      collectionView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tap)))
  }
  
  func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
      print(indexPath)
  }
  
  func tap(sender: UITapGestureRecognizer){
      print("tapped")
  }
  </code></pre>
  
  <h1>Result</h1>
  
  <p>Yeah, it gets in the way now. When you tap on cell, it logs "tapped".</p>
  
  <h1>Analysis</h1>
  
  <ul>
  <li>I check the hitTest return value of the collectionView and the cell. Both returned the tapped cell, which means they form a responder chain of Cell -> CollectionView</li>
  <li>no gestures on the cell</li>
  <li>3 gestures on collectionView, no one seems to work with the cell select
  
  <ul>
  <li>UIScrollViewDelayedTouchesBeganGestureRecognizer</li>
  <li>UIScrollViewPanGestureRecognizer</li>
  <li>UITapGestureRecognizer</li>
  </ul></li>
  <li>callStack, seems cell selection has a different stack trace with gesture's target-action pattern.</li>
  <li>double tap gesture works along with cell selection.</li>
  </ul>
  
  <h1>Question</h1>
  
  <p>Couldn't find more trace. Any ideas on how cell selection is implemented or to achieve this task?</p>