title: How do I scroll the UIScrollView when the keyboard appears?
body: <p>I'm having trouble with my code. I'm trying to move the <code>UIScrollView</code> when I'm editing an <code>UITextField</code> that should be hidden by the keyboard pop.</p>
  
  <p>I'm moving the main frame right now because I don't know how to 'scroll up' in the code.
  So, I did a little bit of code, it's working fine but when I edit an UItextfield and I switch to another <code>UITextField</code> without pressing on the 'return' button the main view goes waaayyyyy to far up.</p>
  
  <p>I did an <code>NSLog()</code> with my variables size, distance and textFieldRect.origin.y as you can see below. When I put two <code>UITextField</code> at the same place (y origin) and I do this particular 'switch' (wihtout pressing return) , I get the same numbers, whereas my code worked fine for the first <code>UITextField</code> editing but not for the second editing.</p>
  
  <p>Check this out:</p>
  
  <pre><code>- (void)textFieldDidBeginEditing:(UITextField *)textField {
  {
      int size;
      CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];
      size = textFieldRect.origin.y + textFieldRect.size.height;
      if (change == FALSE)
      {
          size = size - distance;
      }
      if (size &lt; PORTRAIT_KEYBOARD_HEIGHT)
      {
          distance = 0;
      }
      else if (size &gt; PORTRAIT_KEYBOARD_HEIGHT)
      {
          distance = size - PORTRAIT_KEYBOARD_HEIGHT + 5; // +5 px for more visibility
      }
      NSLog(@"origin %f", textFieldRect.origin.y);
      NSLog(@"size %d", size);
      NSLog(@"distance %d", distance);
      CGRect viewFrame = self.view.frame;
      viewFrame.origin.y -= distance;
      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationBeginsFromCurrentState:YES];
      [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
      [self.view setFrame:viewFrame];
      [UIView commitAnimations];
      change = FALSE;
  }
  
  - (void)textFieldDidEndEditing:(UITextField *)textField
  {
      change = TRUE;
      CGRect viewFrame = self.view.frame;
      viewFrame.origin.y += distance;
      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationBeginsFromCurrentState:YES];
      [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
      [self.view setFrame:viewFrame];
      [UIView commitAnimations];
  }
  </code></pre>
  
  <p>Any ideas ?</p>