title: UICollectionView crashing when scrolling whist rotating (layout attributes for supplementary item at index path changed without invalidating..)
body: <p>Any ideas how to resolve the fact my UICollectionView crashing when scrolling whist rotating?</p>
  
  <p>I am using the following approach for scrolling and rotation separately, and each seem to work fine.  I've just noted when doing both things at the same time I can get this crash. So it seems to be something to do with the fact when I rotate the device and the new layout attributes are being calculated within prepareLayout, that the continual scrolling is triggering "invalidateLayoutWithContext(invalidContext)" (see below).  </p>
  
  <p>Ideas?  Is there a way to put any scrolling responses on-hold (or ignore them) during the rotation? </p>
  
  <p><strong>Rotation Approach</strong>
  In viewWillLayoutSubviews in the view controller I invalidate the whole layout</p>
  
  <pre><code>self.cal.collectionViewLayout.invalidateLayout()
  </code></pre>
  
  <p><strong>Scrolling Approach</strong>
  To allow me to have a "sticky" decorative view (header) I don't invalidate the whole layout, as it kills performance, but do the following.  In the layout class I override shouldInvalidateLayoutForBoundsChange</p>
  
  <pre><code>    override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -&gt; Bool {
          let invalidContext : UICollectionViewLayoutInvalidationContext = self.invalidationContextForBoundsChange(newBounds)
  
          // Keep Header Sticky
  invalidContext.invalidateDecorationElementsOfKind(GCCalendarLayoutKind_Decorative1, atIndexPaths: [headerDecorativeIndexPath])
  
          // Apply Invalidation
          self.invalidateLayoutWithContext(invalidContext)        
  
          // Return normal super return (just in case of future IOS upgrades)
          return super.shouldInvalidateLayoutForBoundsChange(newBounds)
      }
  </code></pre>
  
  <p>Note here I'm invalidating the Decorative View (header), whereas the error with the crash is about my supplementary view layouts being different.  </p>
  
  <p><strong>Error</strong></p>
  
  <blockquote>
    <p>2015-10-30 07:14:30.181 test3_collectionview[17086:3102132] <strong>*
    Assertion failure in -[UICollectionViewData validateLayoutInRect:],
    /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UICollectionViewData.m:408
    2015-10-30 07:14:30.185 test3_collectionview[17086:3102132] *</strong>
    Terminating app due to uncaught exception
    'NSInternalInconsistencyException', reason: 'layout attributes for
    supplementary item at index path ( {length =
    2, path = 0 - 0}) changed from
     index
    path: ( {length = 2, path = 0 - 0}); element
    kind: (Decorative1); frame = (0 1085.5; 320 16); zIndex = 1;  to
     index
    path: ( {length = 2, path = 0 - 0}); element
    kind: (Decorative1); frame = (0 853.5; 320 16); zIndex = 1;  without
    invalidating the layout'
    *** First throw call stack:</p>
  </blockquote>