Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the frame of the keyboard dynamically

Is it possible to get the frame, actually its height, of the keyboard dynamically? As I have a UITextView and I would like to adjust its height according to the keyboard frame height, when the input method of the keyboard is changed. As you know, different input methods may have different keyboard frame height.

like image 731
lu yuan Avatar asked Aug 16 '12 14:08

lu yuan


People also ask

How do you measure height of keyboard?

In the proper position, the keyboard should be placed just above the level of your lap. This is lower than most people normally place their keyboard, but lets your arms tilt downward while using the keyboard, leaving your elbows at a comfortable "open" angle.

How do I find the size of the keyboard in Swift?

To configure the size of the keyboard, you need to open the SwiftKey app, then tap “Layout & keys”. Tap “Layout & keys” in the SwiftKey app to get to the keyboard resizing settings. Once in the layout and keys menu, tap the top option “Resize”, to configure the size of your keyboard.

What is the height of keyboard in IOS?

The universal height of the letters view on iPhone is of 216 points in portrait and 162 points in landscape. On iPad it's 264 points in portrait and 352 points in landscape (these heights don't include top the number row).

How do you dismiss a keyboard in Swift?

Via Tap Gesture This is the quickest way to implement keyboard dismissal. Just set a Tap gesture on the main View and hook that gesture with a function which calls view. endEditing .


1 Answers

try this:

[[NSNotificationCenter defaultCenter] addObserver:self                                      selector:@selector(keyboardWasShown:)                                          name:UIKeyboardDidShowNotification                                        object:nil];  - (void)keyboardWasShown:(NSNotification *)notification {  // Get the size of the keyboard. CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;  //Given size may not account for screen rotation int height = MIN(keyboardSize.height,keyboardSize.width); int width = MAX(keyboardSize.height,keyboardSize.width);  //your other code here.......... } 

Tutorial for more information

like image 105
Hector Avatar answered Oct 17 '22 20:10

Hector