in my view i have 14 text fields in a scrollview.
To move the view up /down while keyboard appears/ disappears i have set the scroll view frame sizes
#pragma mark - Text field view delegate methods
- (void)textFieldDidBeginEditing:(UITextField *)textField;
{
//To move the scroll view up to avoid keybord covers the text field
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
//scrollView.frame = CGRectMake(scrollView.frame.origin.x, (scrollView.frame.origin.y - 45), scrollView.frame.size.width, scrollView.frame.size.height);
[scrollView setContentSize:CGSizeMake(200, 1100)];
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField;
{
//To move the view down
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
[scrollView setContentSize:CGSizeMake(200, 900)];
//scrollView.frame = CGRectMake(scrollView.frame.origin.x, (scrollView.frame.origin.y + 45), scrollView.frame.size.width, scrollView.frame.size.height);
[UIView commitAnimations];
}
for return key board focussed to the next field and for the last field keyboard resign
- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
if(textField == nameField) {
[emailText becomeFirstResponder];
} else if(textField == emailText) {
[mobileText becomeFirstResponder];
}
else if(textField == mobileText) {
[iPhoneText becomeFirstResponder];
}
else if(textField == iPhoneText.value) {
[companyText becomeFirstResponder];
}
else if(textField == companyText) {
[roleText becomeFirstResponder];
}
...
......
...........
else if(textField == lastfield) { // Last fiels
[textField resignFirstResponder];
}
return YES;
}
But my intension is when ever a text field is focussed that text field is moving up to the keyboard top or center of the view
How to do it
I use TPKeyboardAvoiding for my apps, it seems to work perfectly for me, perhaps give it a try.