I have a UIScrollView that has several text fields in it, and when the user touches some of the them the keyboard comes out and obscures the text field. So I have implemented code in the UITextFieldDelegate method textFieldDidBeginEditing to automatically shift the content view such that the entry field is visible above the keyboard. This works well, but now I have found that it has one bad side affect -- after repositioning the view I find that if I touch a different text field the focus does not leave the current text field that has focus. After experimenting a bit it seems that this is happening because the view system does not map my touch to the field that is now visible at the point I touched. So I assume that my implementation of shifting the content view is flawed in some regard. If someone could point out what I've done wrong, or provide an alternate implementation that would be great. Here is my code:
Code:
-(void)textFieldDidBeginEditing:(UITextField *)textField {
/* scroll so that the field appears in the viewable portion of screen when the keyboard is out */
UIScrollView* v = (UIScrollView*) self.view ;
CGPoint pt ;
if {
CGRect rc = [textField bounds];
rc = [textField convertRect:rc toView:v];
CGPoint pt = rc.origin ;
pt.x = 0 ;
pt.y -= 60 ;
[v setContentOffset:pt animated:YES];
}
return;
}