I have found that UIKeyboardWillShowNotification and UIKeyboardDidShowNotification are not generated when an undocked/split keyboard appears in iOS 5. For instance, tap into a text field to show the keyboard (notifications are generated), undock the keyboard, tap out of the text field to dismiss the keyboard, tap on the text field again to show the undocked keyboard (notifications are not generated).
Is there any way to detect when the keyboard appears regardless of whether it is docked or not?
You need to observe UIKeyboardWillChangeFrameNotification and UIKeyboardDidChangeFrameNotification instead. When you get them, you can look at the value for UIKeyboardFrameEndUserInfoKey (if it exists, it doesn't always while dragging the keyboard) and see if that rect intersects the window to see if the keyboard is now on or off screen.
If the keyboard appears undocked / split, you don't need to detect it. The whole point of the undocked / split keyboard is that the user can move it freely if it's in the way.
Related
In my iPhone APP I have a view with a textfield and a button (to remove the view).
My main goal is to have the keyboard always visible.
I made a "Send" button visible on the keyboard and am able to capture when the send button is pressed.
Hoever, when you press the send button the keyboard is removed. What I would like is for the keyboard to remain visible and the text from the textfield to be cleared and be textfield to have focus ready for some more typing.
Adding:
[textChat becomeFirstResponder];
in the Did End On Exit event does not work. I am not sure if I should be using one of the other events.
There are a ton of samples and tutorials on how to remove the keyboard, not one on how to keep it.
The keyboard is removed when it stops being the first responder. There is a delegate method you can implement, textFieldShouldEndEditing:, which is called when the text field is asked to resign from being first responder. You could implement this and have it return NO after you do whatever you want to do with the data in the text field (send it somewhere), clear the field, etc.
I've been searching, but haven't quite found a complete answer, and the Apple docs aren't much help.
I have an application with a UIView that has a lot of text fields on it, ranging from the top of the view to the bottom. When the user clicks the first UITextField the keyboard pops up. The keyboard has three buttons above it, previous, next, and done on a toolbar InputAccessoryView.
Basically, let's say there are 6 UITextField boxes that space from the top of the view to the bottom. When the user gets past the third text field, the keyboard blocks the bottom three. How do I have the view adjust up when putting text in the bottom three text fields?
You need to place your textfields into a UIScrollView, and either translate the view above the keyboard when it is active and away when it is down, or another solution such as always having the keyboard up on that page, which'll save you the setFrame calls on your UIView/UIScrollView depending on what the keyboard is doing.
This will further help:
How to adjust the view position when the keyboard opens in iPhone?
I have an app that has a scrollview with a bunch of different textviews in it (when you click on each one, a keyboard pops up and you can type into the textview). See the following pic:
Here's my problem. If I enter any more text than is entered there in the pic, it goes underneath the keyboard so you can't see what you're typing. Is there any way I can make it so that when you're typing and you get down to that last line the the pic, it will automatically continue to scroll up one line at a time so that it always shows what you're typing (with the most recent line right above the keyboard)?
The best thing to do is to resize the textview when it becomes the first responder and when it resigns as first responder.
Resize the textview to fit within visible area when the keyboard is showing
Resize the textview to it's original size when done is pressed.
Check out this post as well.
How to make a UITextField move up when keyboard is present?
I need to have textfield (maybe with button) fixed at the bottom of screen, and when start editing, I want it (and probably the whole view) to move with keyboard up - just like in the native Messages application (or Whatsapp, etc...). Any suggestions ?
The easiest way is to put everything in a UIScrollView, which you resize when the keyboard is shown using the UIKeyboardDidShowNotification. Then you scroll to ensure that your views are visible.
Check out the Apple documentation under "Moving Content That Is Located Under the Keyboard"
I want to add a text box and a button beside it. They will be at the bottom of the window. Then, when I touch the textbox (to type something), keyboard will appear and the whole row (with textbox and button) scrolls up and the keyboard will be right below them. Could you please let me know how can I do that?
Is there any sample program?
Thanks.
Matt Gallagher posted this on his blog:
Sliding UITextFields around to avoid the keyboard
It is a step by step example of exactly what you want.
In the XCode documentation iPhone Application Programming Guide there is a section on "Moving Content That Is Located Under the Keyboard" that talks about receiving keyboard notifications when a keyboard is about to show. There's code there to show you how to get the keyboard size (which varies depending on the orientation). I won't repeat it here.
You can use the same technique to get the UIKeyboardWillShowNotification notification and get the height of where the keyboard will end up. That gives you the bottom edge of where your view needs to go, effectively putting it above the keyboard. So just put your textbox and button inside a view. When you get the notification tell your view where it needs to go (keyboard height + height of the container view) and you're done. You'll also want to catch UIKeyboardWillHideNotification to move the view back to where it was, so keep track of the original container view position.
It's pretty straightforward and it'll look nice, especially if you use a nice UIView animation effect and set the timing just right.