title: Scrolling content hidden by keyboard. xcode 4.3.2
body: <p>Using xcode 4.3.2. I hope this is the last time I have to beg for help.</p>
  
  <p>I have a screen with 4 text fields. The bottom 2 are hidden by the keyboard when editing. I want to be able to scroll down so these 2 hidden fields can be edited. I have pasted my .m and .h files. something is not quite right.</p>
  
  <p>Viewcontroller.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface ViewController : UIViewController;
  @property (strong, nonatomic) IBOutlet UIScrollView *scrollview;
  @property (strong, nonatomic) IBOutlet UITextField *TextField1;
  @property (strong, nonatomic) IBOutlet UITextField *TextField2;
  @property (strong, nonatomic) IBOutlet UITextField *TextField3;
  @property (strong, nonatomic) IBOutlet UITextField *TextField4;
  @property (strong, nonatomic) IBOutlet UITextField *activefield;
  
  - (IBAction)HideKeyBoard:(id)sender;
  </code></pre>
  
  <p>viewcontroler.m</p>
  
  <pre><code>@interface ViewController ()
  @end
  @implementation ViewController
  
  @synthesize scrollview;
  @synthesize TextField1;
  @synthesize TextField2;
  @synthesize TextField3;
  @synthesize TextField4;
  @synthesize activefield;
  
  
   - (void)viewDidLoad
  
  {   
  
  [super viewDidLoad];
  // Do any additional setup after loading the view, typically from a nib.
  }
  
  
  
  - (void)textFieldDidBeginEditing:(UITextField *)textField
  {
  activefield = textField;
  }
  - (void)textFieldDidEndEditing:(UITextField *)textField
  {
  activefield = nil;
  }
  - (void)registerForKeyboardNotifications
  {
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(keyboardWasShown:)
                                                   name:UIKeyboardDidShowNotification object:nil];
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(keyboardWillBeHidden:)
                                                   name:UIKeyboardWillHideNotification object:nil];
  }
  // Called when the UIKeyboardDidShowNotification is sent.
  - (void)keyboardWasShown:(NSNotification*)aNotification
  {
      NSDictionary* info = [aNotification userInfo];
      CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey]
                       CGRectValue].size;
      UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
      scrollview.contentInset = contentInsets;
      scrollview.scrollIndicatorInsets = contentInsets;
      // If active text field is hidden by keyboard, scroll it so it's visible
      // Your application might not need or want this behavior.
      CGRect aRect = self.view.frame;
      aRect.size.height -= kbSize.height;
      if (!CGRectContainsPoint(aRect, activefield.frame.origin) ) {
          CGPoint scrollPoint = CGPointMake(0.0,
                                            activefield.frame.origin.y-kbSize.height);
          [scrollview setContentOffset:scrollPoint animated:YES];
  
      }     
  
  }
  
  // Called when the UIKeyboardWillHideNotification is sent
  - (void)keyboardWillBeHidden:(NSNotification*)aNotification
    {
     UIEdgeInsets contentInsets = UIEdgeInsetsZero;
   scrollview.contentInset = contentInsets;
   scrollview.scrollIndicatorInsets = contentInsets;
   }
  
  
   - (void)viewDidUnload
   {
  
  [self setScrollview:nil];
  [self setActivefield:nil];
  [self setTextField1:nil];
  [self setTextField2:nil];
  [self setTextField3:nil];
  [self setTextField4:nil];
  [super viewDidUnload];
  // Release any retained subviews of the main view.
  }
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
   {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  }
  
  - (IBAction)HideKeyBoard:(id)sender {
  
  }
  
  
  @end
  </code></pre>