title: Size of UICollectionView is sometimes wrong
body: <p>Here is my problem: I'm developing a Kodi Remote on iOS (<a href="http://forum.kodi.tv/showthread.php?tid=235973" rel="nofollow">http://forum.kodi.tv/showthread.php?tid=235973</a>) and everything run pretty well (a classic development) but I'm having a behavior that I can't explain.</p>
  
  <p>I have multiple view controllers; in one of them (a UIViewController containing a UICollectionView), I implemented this delegate method :</p>
  
  <pre><code>- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      CGSize originalSize = [(UICollectionViewFlowLayout *)collectionViewLayout itemSize];
      CGSize collectionViewSize = [collectionView frame].size;
  
      CGFloat interItemSpacing = [(UICollectionViewFlowLayout *)collectionViewLayout minimumInteritemSpacing];
  
      UICollectionViewFlowLayout *collectionViewFlowLayout = (UICollectionViewFlowLayout *)[[self collectionView] collectionViewLayout];
      UIEdgeInsets sectionInset = [collectionViewFlowLayout sectionInset];
  
      CGFloat usableWidth = (collectionViewSize.width - ((kColumns - 1) * interItemSpacing) - sectionInset.left - sectionInset.right);
      CGFloat width =  usableWidth / kColumns;
      CGFloat height = width * originalSize.height / originalSize.width;
  
      return CGSizeMake(width, height);
  }
  </code></pre>
  
  <p>I get the collection view frame (bounds is the same, of course, I don't need origin) and it works great. I get on an iPhone 5 simulator 288 width for a no matter height.</p>
  
  <p>BUT, in a copy-paste of the view controller in the storyboard, I get a 304 width. The weirdest behavior is that with FLEX, and after the render, the collection view measures 288 pixels.</p>
  
  <p>The "only" difference is that the first view controller is just pushed, the second is contained in a UITabBarController.</p>
  
  <p>PS : the first screen I'm talking about are the 3rd &amp; 4th screenshots.</p>
  
  <p>If someone has an explication to this, I'll take it ;)</p>
  
  <p>Update 1 :</p>
  
  <p>If I invalidate the collection view layout in - (void)viewDidLayoutSubviews, items are correctly drawn BUT there is like a flash because the whole collection view is redrawn (the header &amp; items below).</p>