title: Animating scroll view height - content suddenly jumps up prior to animation
body: <p>Here are some screenshots of what's happening.</p>
  
  <p>The green background is a view in the scrollview (i.e. marks the "content size" and "content offset").</p>
  
  <p>The orange is the scroll view frame.</p>
  
  <p><strong>The keyboard is up... the scroll view has scrolled the content nicely.</strong></p>
  
  <p><img src="https://i.stack.imgur.com/zY40b.png" alt="enter image description here"></p>
  
  <p><strong>Now I click off the text field and the keyboard starts to hide</strong></p>
  
  <p><img src="https://i.stack.imgur.com/vN9nZ.png" alt="enter image description here"></p>
  
  <p>Although the scroll view (orange) seems to be the right height, the content has now jumped up about 100px (green).</p>
  
  <p>I have no idea what's causing this - whether its an ios bug or what (it happens on my device as well).</p>
  
  <p>This is the code which resizes the view based on when the keyboard gets shown/hidden.</p>
  
  <pre><code>- (void)keyboardWillShow:(NSNotification *)notif {
      [self.mainScrollView setAutoresizesSubviews:NO];
      // get the scroll view frame size
      CGRect frame = [self.mainScrollView frame];
      frame.size.height = self.view.frame.size.height-216;
  
      [UIView beginAnimations:@"scrollViewAnimations" context:nil];
      [UIView setAnimationDuration:0.3];
      [self.mainScrollView setFrame:frame];
      [UIView commitAnimations];
  
      // add tap gesture recognizer
      _tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_dismissKeyboard:)];
      [_tap setDelegate:self];
      [self.view addGestureRecognizer:_tap];
  }
  
  - (void)keyboardWillHide:(NSNotification *)notif {
      CGRect frame = [self.mainScrollView frame];
      frame.size.height = self.view.frame.size.height;
  
      [UIView beginAnimations:@"scrollViewAnimations" context:nil];
      [UIView setAnimationDuration:0.3];
      [self.mainScrollView setFrame:frame];
      [UIView commitAnimations];
  
      [self.view removeGestureRecognizer:_tap];
  }
  </code></pre>
  
  <p>Any help or guidance would be great, thank you! Why is it doing this? Is it a bug - is it something buried in my code somewhere? I can't find it if it is. Is this an error with the way I'm doing my view animations?</p>