title: Moving UIView up when UITextField is selected
body: <p>I am trying to programatically create some text fields. They appear at the bottom of the screen and when selected the keyboard covers them. I need to move the view up when the textfield is selected. </p>
  
  <p>Here is my code for the View:</p>
  
  <p>Header:</p>
  
  <pre><code>@interface MESLoginViewController : UIViewController &lt;PFLogInViewControllerDelegate, UITextFieldDelegate&gt; {
      IBOutlet UITextField *usernameField;
  }
  </code></pre>
  
  <p>Imp View file:</p>
  
  <pre><code>// Create sub view for Logo
      UIView *logoView =[[UIView alloc] initWithFrame:CGRectMake(0,0,320,280)];
      [logoView setBackgroundColor:[UIColor blueColor]];
      logoView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  
      // Create sub view for fields
      UIView *fieldView = [[UIView alloc] initWithFrame:CGRectMake(0, logoView.bounds.size.height, 320, 200)];
      [fieldView setBackgroundColor:[UIColor greenColor]];
      fieldView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin;
  
      // Setting up the text fields
      // Username field
      usernameField = [[UITextField alloc] initWithFrame:CGRectMake(10, 20, 300, 40)];
      usernameField.borderStyle = UITextBorderStyleRoundedRect;
      usernameField.textColor = [UIColor blackColor];
      usernameField.font = [UIFont systemFontOfSize:17.0];
      usernameField.placeholder = @"Username";
      usernameField.backgroundColor = [UIColor whiteColor];
      usernameField.autocorrectionType = UITextAutocorrectionTypeNo;
      usernameField.keyboardType = UIKeyboardTypeDefault;
      usernameField.returnKeyType = UIReturnKeySearch;
      usernameField.clearButtonMode = UITextFieldViewModeWhileEditing;
      usernameField.delegate = self;
  
      // Password field
      UITextField *passwordField = [[UITextField alloc] initWithFrame:CGRectMake(10, (usernameField.bounds.size.height + 30), 300, 40)];
      passwordField.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin;
      passwordField.borderStyle = UITextBorderStyleRoundedRect;
      passwordField.textColor = [UIColor blackColor];
      passwordField.font = [UIFont systemFontOfSize:17.0];
      passwordField.placeholder = @"Password";
      passwordField.backgroundColor = [UIColor whiteColor];
      passwordField.autocorrectionType = UITextAutocorrectionTypeNo;
      passwordField.keyboardType = UIKeyboardTypeDefault;
      passwordField.returnKeyType = UIReturnKeySearch;
      passwordField.clearButtonMode = UITextFieldViewModeWhileEditing;
      passwordField.delegate = self;
  
      // Add fields/button to fieldView
      [fieldView addSubview:usernameField];
      [fieldView addSubview:passwordField];
  
      // Add subviews to main view
      [self.view addSubview:logoView];
      [self.view addSubview:fieldView];
  </code></pre>
  
  <p>I have added this method for moving the view but cannot correctly work out the last part:</p>
  
  <pre><code>- (void)textFieldDidBeginEditing:(UITextField *)textField{
      NSLog(@"textFieldDidBeginEditing");
      //If we begin editing on the text field we need to move it up to make sure we can still
      //see it when the keyboard is visible.
      //I am adding an animation to make this look better
      [UIView beginAnimations:@"Animate Text Field Up" context:nil];
      [UIView setAnimationDuration:.3];
      [UIView setAnimationBeginsFromCurrentState:YES];
  
      usernameField.frame = CGRectMake(usernameField.frame.origin.x,
                                          -200,
                                          usernameField.frame.size.width,
                                          usernameField.frame.size.height);
  
      [UIView commitAnimations];
  
  }
  </code></pre>
  
  <p>What I am actually looking for is to completely shift the view, or possible change it to a scrollable area above. Although I do implement another method after touch to endEditing. </p>
  
  <p>It seems if I move one field I would have to complete code to move all... How can I just move the view (complete view)?</p>
  
  <p>Also what is needed for the view to return to normal state in the method textFieldDidEndEditing|textFieldShouldEndEditing?</p>