title: Animated 'collapse' of a UICollectionViewCell
body: <p>I have a UICollectionView with in the first, view-wide, cell an image. Now the image has to disappear from sight after entering, animated.</p>
  
  <p>My first thought was to just delete the cell. The animation for that looks exactly like what I want. Except a huge amount of code is dependant on the amount of cells being static. Perhaps things should have been designed differently from the start. Alas, it's too late for that now. </p>
  
  <p>My second thought was to make the height of the cell 0. I wrote an animation for that, based on <a href="https://stackoverflow.com/a/13782805/5324371">this answer</a>, but I can't seem to get it to work. The animation seems instant and I have no idea how to get the rest of the UICollectionView to animate with it.</p>
  
  <p>Here is my existing code:</p>
  
  <pre><code>// version 1
  - (void)viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];
      if (self.needToClearImage) {
          self.needToClearImage = NO;
          void (^compressCell)() = ^() {
              [self.collectionViewGrid reloadData];
          };
  
          [UIView transitionWithView:cellToCompress duration:2.0f options:UIViewAnimationOptionCurveLinear animations:compressCell completion:nil];
       }
  }
  
  // version 2
  - (void)viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];
      if (self.needToClearImage) {
          self.needToClearImage = NO;
          UICollectionViewCell *cellToCompress = [self.collectionViewGrid cellForItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
          void (^compressCell)() = ^() {
              CGRect frame = cellToCompress.frame;
              frame.size = CGSizeMake(0, 0);
              cellToCompress.frame = frame;
          };
  
          [UIView transitionWithView:cellToCompress duration:2.0f options:UIViewAnimationOptionCurveLinear animations:compressCell completion:nil];
       }
  }
  
  // used in both versions
  - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
      if ([indexPath row] == 0 &amp;&amp; self.needToClearImage == NO) {
          return CGSizeMake(self.collectionViewGrid.frame.size.width, 0);
      }
      else {
          ...
      }
  }
  </code></pre>
  
  <p>Edit:</p>
  
  <pre><code>- (void)viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];
      if (self.needToClearImage) {
          self.needToClearImage = NO;
          [self.collectionViewGrid performBatchUpdates:^{
          } completion:^(BOOL finished) {
          }];
      }
  }
  </code></pre>
  
  <p>Calling <code>performBatchUpdates</code> seems to animate the updating of the <code>UICollectionView</code>. It does not however animate the disappearing of the image.</p>