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!
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 ><
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)
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)
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.
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.
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.
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.
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.
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.
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?