Get Keyboard size without showing it - ios

I can get the keyboard's dimension after its displayed from the notification, BUT I would like to position my textFields so that I don't have to scroll them when the keyboard appears. To achieve this I should know the keyboard's dimension BEFORE it's even displayed.
Is this possible on iOS?

You can use a class where this all things are handled by default. Just you have to use scroll view for this.
TPKeyboardAvoidingScrollView
See if it's useful and fulfill your requirement.

Related

iOS - top cells moved up away from the screen when keyboard shows

Here is before the keyboard shows:
Here is after the keyboard shows:
Here is what I want:
If there are enough messages, when move all of them up. If not, like shown in these two images above, then do not move the messages up.
What should I do?
By the way, I use Swift.
Thank you so much!
Because i can't add a comment. so i had to help you in this way.
You can provide us more information about table view's constraint. because if you listening keyboard notification and change constraint, maybe will become like this
If you use frame property to build this, the same point with first
You can run project and use xcode's Debug view hierarchy tool, to check tableview's state. check it's because table view's frame change and be clipped or you change table view's contentInset or other properties to made it ,like this

How to move my chat input bar up on top with keyboard in Xcode?

I create a chat program. I've created my chat sequence using TableView. Now I have a view on the bottom of the page, contains one TextField and a send button. Now if I press on the TextField, the keyboard appears. I need to:
reduce the height of the tableView so that I still can see the most recent chat message, and return it to its former height if the keyboard is hidden.
move the view up to sit on top of the keyboard, and return it to its former position if the keyboard is hidden.
do both of things above with animation.
I'm still newbie in this keyboard + animation area. I only know I will need to implement textFieldDidBeginEditing and textFieldDidEndEditing to do this. But I don't know what code I should implement inside it. This answer provided some, but not the exact answer to my problem (it only moves the floating TextField in the scrollable view of TableView to be within the visible area, not moving a view not related with TableView). Any help or even article will be appreciated. Thanks!

UIKeyboard will change frame with interactive keyboard dismiss, not called continuously

I am trying to use the UITableView.keyboardDismissMode = UIScrollViewKeyboardDismissMode.Interactive, to be able to drag my keyboard up and down. However I can't find any way to track the keyboard frame to update my tableView frame and messaging view. I am simply trying to replicate the standard iMessage behaviour. Given the name, I would have thought that UIKeyboardWillChangeFrameNotification would have been perfect for tracking the keyboard frame changes, but it only notifies when the gesture ends and the keyboard animates up or down.
I'm not sure if this will work but you could try to track the drag progress via the panGesture property on UIScrollView in your tableView. It wouldn't be a direct tracking of the keyboard frame, but if you know the keyboard's height and the progress/offset of the pan, you might be able to math your way around the problem.
The best approach for interactive dismissal is to use the "UIKeyboardDidShowNotification" and "UIKeyboardWillHideNotification" system notifications. When the selector is called you update the table's bottom inset. NOT the constraints. Updating the inset will give you a beautiful smooth keyboard dismissal experience.

iOS 8 get keyboard height

I'm having trouble reliably getting the actual height of the keyboard. I'm adding a custom toolbar that is meant to be placed directly above the keyboard. To do so with layout constraints, I've added a static space constraint between the bottom of the screen and the bottom of the toolbar. When the keyboard is displayed, I modify this constraint to be the height of the keyboard, which varies quite a bit in iOS 8.
To resize the spacer, I currently use the following method that gets fired on UIKeyboardDidShowNotification
-(void)keyboardDidShow:(NSNotification*)notification
{
CGFloat height = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].height;
self.shimConstraint.constant = height;
[self.view layoutIfNeeded];
}
This does resize the constraint correctly sometimes, but often the keyboard height returned is entirely incorrect. What is the best way to reliably get the height of the keyboard once it is displayed?
EDIT: The application allows the user to switch between a number of different input fields. Some of them have autocorrect disabled, so the autocorrect bar may or may not be hidden, and incorrect heights are returned when switching fields.
The way you are doing it is correct but you might want to use UIKeyboardFrameEndUserInfoKey instead of UIKeyboardFrameBeginUserInfoKey. The end user key is the frame of the keyboard when it is done animating and on the screen, thus you know it will be that frame, while the begin key might not always match what the keyboard frame will be when it is shown.
There might also need to be extra considerations on orientation of the device, I have not looked into that, but for portrait, it should work.
The correct way to do this is to use the inputAccesorryView property of the UITextField.
The inputAccessoryView is automatically added above the keyboard regardless of keyboard size.
As the documentation states:
The default value of this property is nil. Assigning a view to this property causes that view to be displayed above the standard system keyboard (or above the custom input view if one is provided) when the text field becomes the first responder. For example, you could use this property to attach a custom toolbar to the keyboard
See more information here
https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html
You might need to do [self.view setNeedsLayout] instead of [self.view layoutIfNeeded].

How to get rid of space between UITextField and Keyboard

I was wondering if anyone has seen a similar problem to this where you have a random blank space between the keyboard and a UITextField? For some reason I can't find anything about this and the end of the screen is the bottom of the UITextField. Any help would be greatly appreciated.
Example Screenshot showing space between keyboard and UITextField
Start by putting the text field in a UIScrollView.
Register your view controller to respond to the notification UIKeyboardDidShowNotification. This notification will give you a dictionary that has the size of the keyboard.
Once you have the size value, you will have to do some math to figure out what you want the scroll view's contentInset to be such that the text field is just above it.
Here's an example for getting the size of the keyboard: How to get UIKeyboard size with Apple iPhone SDK

Resources