Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 9, 2008, 08: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 09:12 AM.
beachdog is offline   0 Reply With Quote
Old Oct 11, 2008, 07: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, 08: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, 12: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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Snow Leopard PPP "Connect automatically when needed" is inactive Žalgiris Mac OS X 0 May 9, 2011 01:54 AM
scroll a uitextfield and a uitextview in a uiscrollview franium iPhone/iPad Programming 14 Dec 4, 2010 02:51 AM
mbp powers up automatically when magsafe is plugged oYx MacBook Pro 0 Mar 28, 2010 11:48 PM
is there an event when keyboard comes out or retracts beachdog iPhone/iPad Programming 1 Oct 17, 2008 05:16 PM
Safari closes automatically when it is in use y2knp iPhone Tips, Help and Troubleshooting 6 Oct 5, 2008 11:12 PM


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

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

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC