 |
 |
|
 |
07-01-2008, 10:54 AM
|
#1 (permalink)
|
|
New Member
Join Date: Jul 2008
Posts: 31
|
Keyboard hides text field - how do I fix this?
In the apple applications, when clicking on a text field, that field becomes centered in the view, with the keyboard below it. How do I do this in one of my own apps? When I click on the text field, the keyboard appears, but it appears right over the text field!
Thanks!
|
|
|
07-01-2008, 11:50 AM
|
#2 (permalink)
|
|
Registered Member
Join Date: Apr 2008
Location: Colorado
Posts: 313
|
Re: Keyboard hides text field - how do I fix this?
Shift the frame of the view the text field is in up when the keyboard appears. You will want to do this in the textfield's delegate methods. It is kind of a huge pain though, I try to avoid having to do this if at all possible. Sometimes those text fields only really fit in the layout at the bottom of a view ><
|
|
|
07-01-2008, 12:13 PM
|
#3 (permalink)
|
|
New Member
Join Date: Jul 2008
Posts: 31
|
Re: Keyboard hides text field - how do I fix this?
Quote:
|
Originally Posted by jonc
Shift the frame of the view the text field is in up when the keyboard appears. You will want to do this in the textfield's delegate methods. It is kind of a huge pain though, I try to avoid having to do this if at all possible. Sometimes those text fields only really fit in the layout at the bottom of a view ><
|
What would be the best way to do it? (I am new to Cocoa and Objective-C, and am learning as I go along)
Thanks for the quick reply!
|
|
|
07-01-2008, 01:50 PM
|
#4 (permalink)
|
|
New Member
Join Date: Apr 2008
Posts: 802
|
Re: Keyboard hides text field - how do I fix this?
Do a BeginAnimation, change the frame position, CommitAnimation.
Reverse when putting away the keyboard.
See the various examples (I think UICatalog has an example)
|
|
|
07-01-2008, 11:36 PM
|
#5 (permalink)
|
|
Registered Member
Join Date: Apr 2008
Location: Colorado
Posts: 313
|
Re: Keyboard hides text field - how do I fix this?
I am assuming this is in the controller of the view with the text field and that it isn't a table view.
Code:
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - 100, self.view.frame.size.width, self.view.frame.size.height);
Notice where I subtract 100. That would move it 100 pixels up. Find a value that works well for your view. Add that same value back to origin.y when don and your view will move back down. Throw some animation code around it to make it move smoothly. I have found the keyboard pops up and down in about 0.25 seconds if you want the timing to match the keyboard.
|
|
|
07-02-2008, 07:16 AM
|
#6 (permalink)
|
|
New Member
Join Date: Jul 2008
Posts: 31
|
Re: Keyboard hides text field - how do I fix this?
Quote:
|
Originally Posted by jonc
I am assuming this is in the controller of the view with the text field and that it isn't a table view.
Code:
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - 100, self.view.frame.size.width, self.view.frame.size.height);
Notice where I subtract 100. That would move it 100 pixels up. Find a value that works well for your view. Add that same value back to origin.y when don and your view will move back down. Throw some animation code around it to make it move smoothly. I have found the keyboard pops up and down in about 0.25 seconds if you want the timing to match the keyboard.
|
Thanks! That helped a lot. I liked how Safari would always focus the text above the keyboard, and that helped.
|
|
|
07-02-2008, 08:39 PM
|
#7 (permalink)
|
|
New Member
Join Date: Jul 2008
Posts: 31
|
Re: Keyboard hides text field - how do I fix this?
Ok, so by it helping, it didnt - i think i accidentally scrolled and thought it worked. How do I make it work. I put the code in, but nothing happened.
|
|
|
07-03-2008, 12:57 AM
|
#8 (permalink)
|
|
Registered Member
Join Date: Apr 2008
Location: Colorado
Posts: 313
|
Re: Keyboard hides text field - how do I fix this?
Quote:
|
Originally Posted by pendraggon87
Ok, so by it helping, it didnt - i think i accidentally scrolled and thought it worked. How do I make it work. I put the code in, but nothing happened.
|
Scrolled? What kind of view is the text field on? If it is a scroll view or table you are going to have to do it differently.
Also where are you putting that code?
|
|
|
07-03-2008, 04:11 AM
|
#9 (permalink)
|
|
Registered Member
Join Date: May 2008
Posts: 122
|
Re: Keyboard hides text field - how do I fix this?
I have the same problem with a tableview, the keyboard hides all my textfields when popping up. When editing a mail-account in settings on the iPhone apple have the same problem, they solve it by making it possible to scroll the view over the keyboard when the keyboard popup. But when I try the same I cant scroll to the textfield at the bottom, they are still hidden behind the keyboard. How can I solve this? If you don't understand what I mean, check settings -> mail -> and then edit one of your accounts.
|
|
|
07-03-2008, 07:09 AM
|
#10 (permalink)
|
|
Registered Member
Join Date: Apr 2008
Location: Colorado
Posts: 313
|
Re: Keyboard hides text field - how do I fix this?
Quote:
|
Originally Posted by martinn
I have the same problem with a tableview, the keyboard hides all my textfields when popping up. When editing a mail-account in settings on the iPhone apple have the same problem, they solve it by making it possible to scroll the view over the keyboard when the keyboard popup. But when I try the same I cant scroll to the textfield at the bottom, they are still hidden behind the keyboard. How can I solve this? If you don't understand what I mean, check settings -> mail -> and then edit one of your accounts.
|
Use the code bit I mentioned above to adjust the frame of your table view, but since it is a table view leave origin.y alone and just shrink the size.height enough to account for the height of the keyboard. You will then need to check the table view documentation on how to make the table view scroll to the cell you want because changing the frame will leave a different cell in the middle. You will then want to increase the size.height of the table view when done.
I spent about a week tweaking this behavior and getting it to work right with a table view so don't expect any miracles. Good luck.
|
|
|
07-03-2008, 07:43 AM
|
#11 (permalink)
|
|
New Member
Join Date: Jul 2008
Posts: 31
|
Re: Keyboard hides text field - how do I fix this?
I realized that the reason the code made my view a little wonky was that in fact it was not a scroll view, just a regular viewcontroller, and as such when I moved the frame, part of the display had that gray-striped background, but another part just had a white background - not a nice effect. If I use a scroll view instead, would that make it work better?
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 418 |
| 34 members and 384 guests |
| AdamSubach, aderrington, benoitr007, bensj, BrianSlick, Danneman, dev123, ErichGS, GreatWizard, gustavo7sexton, gw1921, HemiMG, iSDK, Jeremy1026, lifeCoder45, melodizzzy, mriphoneman, newchucky, Ovidius, Piequanna, pofak, qilin, Racker, raheel, rendezvouscp, riq, Sega dude, socals, timle8n1, Whitehk, ZunePod |
| Most users ever online was 965, 06-30-2010 at 04:26 AM. |
» Stats |
Members: 41,861
Threads: 49,770
Posts: 213,057
Top Poster: BrianSlick (3,139)
|
| Welcome to our newest member, melodizzzy |
|