Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

beachdog

macrumors member
Original poster
Aug 10, 2008
86
0
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;
}
 

beachdog

macrumors member
Original poster
Aug 10, 2008
86
0
bump.


Any ideas on how to make this work?

It seems to me that the view the keyboard is in is layered on top of the scrollview that contains the text field, and that therefore the scrollbars of the scrollview do not adjust when the keyboard comes out. I guess that means I should do that manually, but I am neither sure of the code to do that, nor how to programmatically calculate the amount of the view that the keyboard is taking.

An example of an app that does it right is email -- when constructing an email, if you type into the To field the keyboard comes out, and then if you type a letter a tableview of matching contacts appears between the textfield and the keyboard, with proper scrolling.
 

tusharbhatta

macrumors newbie
Jun 23, 2008
4
0
UIScrollView firstResponder hides UITEXTFIELD

Hi,

i am newbie. Could you please help me if you have solved that problem ?


Many thanks..

Tushar
 

mamcx

macrumors regular
Mar 13, 2008
210
28
Hi, any update on this?

I'm stuck on this too. I wonder what to do. No solution I get on the web solve this problem...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.