title: Why does UIScrollView resize back up when moving to another textfield - iOS iPhone
body: <p>This probably isn't an easy one to answer....</p>
  
  <p>I have 8 text fields on screen which sit in a scrollView. When I select the first field, the keyboard appears and the scrollView shrinks. I can then scroll up and down.</p>
  
  <p>When I select another text field, I can't scroll anymore.</p>
  
  <p>I've checked the scrollView height using <code>textFieldDidBeginEditing</code> and it definitely grows back up.</p>
  
  <p>I've also registered for all 4 of the keyboard notifications but none of them are triggered during the move to the new text field.</p>
  
  <p>Any pointers would be much appreciated :)</p>
  
  <pre><code>- (void)viewDidLoad
  {
  [super viewDidLoad];
  
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(keyboardWillShow:)
                                               name:UIKeyboardWillShowNotification
                                             object:self.view.window];
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(keyboardWillHide:)
                                               name:UIKeyboardWillHideNotification
                                             object:self.view.window];
  
  
  keyboardIsShown = NO;
  
  //Additional Code    
  
  }
  
  - (void)viewDidUnload {
  
  [[NSNotificationCenter defaultCenter] removeObserver:self
                                                  name:UIKeyboardWillShowNotification
                                                object:nil];
  
  [[NSNotificationCenter defaultCenter] removeObserver:self
                                                  name:UIKeyboardWillHideNotification
                                                object:nil];
  
  
  }
  
  - (void)keyboardWillHide:(NSNotification *)n
  {
  
  NSDictionary* userInfo = [n userInfo];
  
  CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
  
  CGRect viewFrame = self.scrollView.frame;
  
  viewFrame.size.height += (keyboardSize.height - self.toolBar.frame.size.height);
  
  [self.scrollView setFrame:viewFrame];
  
  keyboardIsShown = NO;
  }
  
  - (void)keyboardWillShow:(NSNotification *)n
  {
  if (keyboardIsShown) {
      return;
  }
  
  NSDictionary* userInfo = [n userInfo];
  
  CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
  
  CGRect viewFrame = self.scrollView.frame;
  
  viewFrame.size.height -= (keyboardSize.height - self.toolBar.frame.size.height);
  
  scrollViewHeight = viewFrame.size.height;
  
  [self.scrollView setFrame:viewFrame];
  
  keyboardIsShown = YES;
  }
  </code></pre>
  
  <p>For moving between the text fields:</p>
  
  <pre><code>-(void)textFieldDidBeginEditing:(UITextField *)textField
  {
  [[self saveButton] setEnabled:YES];
  
  }
  
  -(BOOL)textFieldShouldReturn:(UITextField *)textField
  {
  if (textField == self.label1) {
      [self.label2 becomeFirstResponder];
  } else if (textField == self.label2) {
      [self.label3 becomeFirstResponder];
  } else if (textField == self.label3) {
      [self.label4 becomeFirstResponder];
  } else if (textField == self.label4) {
      [self.label5 becomeFirstResponder];
  } else if (textField == self.label5) {
      [self.label6 becomeFirstResponder];
  } else if (textField == self.label6) {
      [self.label7 becomeFirstResponder];
  } else if (textField == self.label7) {
      [self.label8 becomeFirstResponder];
  } else if (textField == self.label8) {
      [textField resignFirstResponder];
  }
  return YES;
  }
  </code></pre>