Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-17-2011, 06:54 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 1
mdeepaks is on a distinguished road
Default Keyboard hides UITextView in UIScrollView

I have a scrollview and a few UITextFields in it. When I touch inside the UITextField, they keyboard comes up but it obscures some of the UITextFields. I want the text fields to scroll up when the keyboard appears and scroll down when it disappears. I have done this but one thing is not happening. Only when I start typing, the text fields scroll up and the keyboard hides them until then. Rather they have to scroll up as soon as the keyboard appears. I am pasting the code below. Other than this issue, keyboard appears and disappears properly and the text fields scrolls up when I start typing and comes down when I am done.

Here is the code:

Code:
-(void) viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];


[[NSNotificationCenter defaultCenter]

addObserver:self 

selector:@selector

(keyboardWillShow:)

name:UIKeyboardWillShowNotification 

object:nil];



[[NSNotificationCenter defaultCenter]

addObserver:self 

selector:@selector

(keyboardDidHide:)

name:UIKeyboardDidHideNotification

object:nil];


scrollView.contentSize = CGSizeMake(320.0,450.0);

displayKeyboard = NO;

}



-(void) keyboardWillShow: (NSNotification *)notif {

if(displayKeyboard)

return;


NSDictionary* info = [notif userInfo];

NSValue* aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];

CGSize keyboardSize = [aValue CGRectValue].size;


offset = scrollView.contentOffset;


CGRect viewFrame = scrollView.frame;

viewFrame.size.height -= keyboardSize.height;

scrollView.frame = viewFrame;


CGRect textFieldRect = [field frame];

textFieldRect.origin.y += 5;

[scrollView scrollRectToVisible: textFieldRect animated:YES];

displayKeyboard = YES;

}

Appreciate your help!!

Thanks,

Last edited by mdeepaks; 01-20-2011 at 09:56 AM. Reason: Wrapping code tag for better readability
mdeepaks is offline   Reply With Quote
Old 01-17-2011, 07:11 AM   #2 (permalink)
Scan Me !
 
MozyMac's Avatar
 
Join Date: Nov 2009
Posts: 608
MozyMac is on a distinguished road
Send a message via AIM to MozyMac Send a message via MSN to MozyMac Send a message via Yahoo to MozyMac
Default

Just a side note, ALWAYS use CODE tag when pasting code, it makes it much easier for people to help you
MozyMac is offline   Reply With Quote
Reply

Bookmarks

Tags
keyboard hides text field, uiscrollview, uitextfield

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 365
10 members and 355 guests
7twenty7, blueorb, dre, iAppDeveloper, iGamesDev, Mah6447, Morrisone, mottdog, sacha1996, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:37 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0