title: How to move view up when iOS keyboard appears?
body: <p>For a login screen with just three textfields and submit button, I want the view to move up when the keyboard appears just enough so that while the field is not hidden, it also does not move up out of view.</p>
  <p>The amount of movement needed is such that the submit button is a fixed distance above the keyboard.  While it is possible by moving the fields high up on the page to leave room for the keyboard, the submit button is still hidden</p>
  <p>I tried just adding the following:</p>
  <pre><code>-(void) viewWillAppear:(BOOL)Animated {
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
      
  }
  - (void)viewWillDisappear:(BOOL)animated {
      [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
      [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
  }
  </code></pre>
  <p>This moves the view up a fixed amount but so much so that the fields are not visible for editing, i.e. they are too high up.</p>
  <p>Another SO answer suggested:</p>
  <pre><code>-(void)textFieldDidBeginEditing:(UITextField *)textField
  {
      [self animateTextField:textField up:YES];
  }
  
  - (void)textFieldDidEndEditing:(UITextField *)textField
  {
      [self animateTextField:textField up:NO];
  }
  
  -(void)animateTextField:(UITextField*)textField up:(BOOL)up
  {
      const int movementDistance = -200; // tweak as needed
      const float movementDuration = 0.3f; // tweak as needed
      
      int movement = (up ? movementDistance : -movementDistance);
      
      [UIView beginAnimations: @&quot;animateTextField&quot; context: nil];
      [UIView setAnimationBeginsFromCurrentState: YES];
      [UIView setAnimationDuration: movementDuration];
      self.view.frame = CGRectOffset(self.view.frame, 0, movement);
      [UIView commitAnimations];
  }
  </code></pre>
  <p>I can't figure out how to implement this.  If you just leave it as is nothing happens.  I guess you are supposed to rename textfield with the name of your textfield but in that case, would you do it for each of the textfields?  I cannot get it to have any effect.</p>
  <p>Another suggestion is to use a category such as TPKeyboardAvoiding however this requires a scrollview that I do not need in this case.</p>
  <p>Is there no straightforward solution in 2015 for this issue?</p>