Well, you can do this in 2 ways: the easy way, and the hard way.
Easy way: Instead of a ViewController, use a TableViewController and create custom cells that contain the text fields. The TableViewController will take care of moving the view up for you when the keyboard goes up. Then all you have to worry about is to dismiss the keyboard whenever you want the keyboard to go away.
The hard way: Use a ViewController.
In order for this to work you need to have 2 notifications, like this ones (place this inside your viewDidLoad method):
// Keyboard notifications so things can move up when the keyboard shows up
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
Then you need to create the 2 methods you're calling in the NotificationCenter, to actually perform the movement of the screen:
- (void) keyboardWillShow: (NSNotification*) aNotification
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = [[self view] bounds];
rect.origin.y -= 150;
[[self view] setFrame: rect];
[UIView commitAnimations];
}
// Call this to make the keyboard move everything down
- (void) keyboardWillHide: (NSNotification*) aNotification
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = [[self view] frame];
if (rect.origin.y == -150)
{
rect.origin.y += 150;
}
[[self view] setFrame: rect];
[UIView commitAnimations];
}
In this code, the value of 150 is an arbitrary number of points that the keyboard will go up/down. You can change it or do some fancy calculation to get a percentage of the screen regardless of the screen size.
Hope it helps!