Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 9, 2008, 09:41 AM   #1
beachdog
macrumors member
 
Join Date: Aug 2008
scrolling UIScrollView automatically when keyboard is out

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;
}

Last edited by beachdog; Oct 9, 2008 at 10:12 AM.
beachdog is offline   0 Reply With Quote
Old Oct 11, 2008, 08:39 AM   #2
beachdog
Thread Starter
macrumors member
 
Join Date: Aug 2008
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.
beachdog is offline   0 Reply With Quote
Old Dec 27, 2008, 09:38 AM   #3
tusharbhatta
macrumors newbie
 
Join Date: Jun 2008
UIScrollView firstResponder hides UITEXTFIELD

Hi,

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


Many thanks..

Tushar
tusharbhatta is offline   0 Reply With Quote
Old Feb 2, 2009, 01:37 PM   #4
mamcx
macrumors regular
 
Join Date: Mar 2008
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...
mamcx is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Keyboard Lights On Automatically In Bootcamp p3ntyne Windows, Linux & Others on the Mac 1 Apr 16, 2014 05:10 AM
How do you arrange finder windows to automatically "show all" instead of scrolling? DramaLLama OS X 1 Jul 22, 2013 10:30 AM
keyboard no longer disappears when scrolling through messages? joejoejoe iOS 7 0 Jun 10, 2013 05:14 PM
Keyboard and Trackpad automatically go to sleep? ProfNaz Mac Peripherals 4 Jan 9, 2013 04:17 PM

Forum Jump

All times are GMT -5. The time now is 06:51 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC