title: Animation Duration for UICollectionView selectItemAtIndexPath:animated:scrollPosition:
body: <p>I have tried to set the duration (with the normal methods that I would try) for setting the animation duration for UICollectionView's <code>selectItemAtIndexPath:animated:scrollPosition:</code> method (or the <code>scrollToItemAtIndexPath:atScrollPosition:animated:</code> method).  I've tried <code>[UIView setAnimationDuration]</code>, and I've tried wrapping it in a <code>CATransaction</code>.  I've been unsuccessful up to this point at changing that animation duration (although I admit that I could have made a mistake in this logic).</p>
  
  <p>Thoughts?</p>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>I have tried a good number of approaches here.  The closest solution is to do what we would normally do for <code>UIScrollView</code> animation (by setting the animated: argument to <code>NO</code> and wrapping it in a <code>UIView</code> animation block).  This works perfectly fine for the scrollview.  However, this screws with the <code>UICollectionView</code> creation process for some reason.</p>
  
  <p>I have included an example below using two approaches.  Each approach assumes that you have 4 sections with 4 items in each section.  In addition, the animation assumes you are moving from 0,0 to 3,3.</p>
  
  <p><strong>Using Default Animation</strong></p>
  
  <p>Part of the issue here certainly seems tied to <code>UICollectionView</code>.  If you take the following approach (using the default animation option) - all works fine:</p>
  
  <pre><code>[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:3 inSection:3]
                                  atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
                                          animated:YES];
  </code></pre>
  
  <p>When this is being executed, each cell in-between the current visible cells and the destination cell is created.  I have included logging on the <code>collectionView:cellForItemAtIndexPath:</code> method:</p>
  
  <pre class="lang-none prettyprint-override"><code>2013-05-18 09:33:24.366 DEF-CV-Testing[75463:c07] Transition
  Cell Created for Index Path: &lt;NSIndexPath 0x8913f40&gt; 2 indexes [0, 1]
  Cell Created for Index Path: &lt;NSIndexPath 0x75112e0&gt; 2 indexes [0, 2]
  Cell Created for Index Path: &lt;NSIndexPath 0xfe1a6c0&gt; 2 indexes [0, 3]
  Cell Created for Index Path: &lt;NSIndexPath 0x89159e0&gt; 2 indexes [1, 0]
  Cell Created for Index Path: &lt;NSIndexPath 0x8a10e70&gt; 2 indexes [1, 1]
  Cell Created for Index Path: &lt;NSIndexPath 0x7510d90&gt; 2 indexes [1, 2]
  Cell Created for Index Path: &lt;NSIndexPath 0x75112a0&gt; 2 indexes [1, 3]
  Cell Created for Index Path: &lt;NSIndexPath 0x8915a00&gt; 2 indexes [2, 0]
  Cell Created for Index Path: &lt;NSIndexPath 0x75111c0&gt; 2 indexes [2, 1]
  Cell Created for Index Path: &lt;NSIndexPath 0xfe17f30&gt; 2 indexes [2, 2]
  Cell Created for Index Path: &lt;NSIndexPath 0xfe190c0&gt; 2 indexes [2, 3]
  Cell Created for Index Path: &lt;NSIndexPath 0xfe16920&gt; 2 indexes [3, 0]
  Cell Created for Index Path: &lt;NSIndexPath 0x75112a0&gt; 2 indexes [3, 1]
  Cell Created for Index Path: &lt;NSIndexPath 0xfe1a4f0&gt; 2 indexes [3, 2]
  Cell Created for Index Path: &lt;NSIndexPath 0x75142d0&gt; 2 indexes [3, 3]
  </code></pre>
  
  <p><strong>Using Custom Animation</strong></p>
  
  <p>When wrapping the <code>scrollToItemAtIndexPath:</code> method in a <code>UIView</code> animation block, items are not created correctly.  See code sample here:</p>
  
  <pre><code>[UIView animateWithDuration:5.0 delay:0.0 options:0 animations:^{
      [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:3 inSection:3]
                                  atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
                                          animated:NO];
  } completion:^(BOOL finished) {
      NSLog(@"Completed");
  }];
  </code></pre>
  
  <p>The currently visible cells disappear and only the destination one is created.  I have included the same logging on the <code>collectionView:cellForItemAtIndexPath:</code> method:</p>
  
  <pre class="lang-none prettyprint-override"><code>Transition
  Cell Created for Index Path: &lt;NSIndexPath 0x71702f0&gt; 2 indexes [3, 3]
  Completed
  </code></pre>