Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the height of iPhone's onscreen keyboard?

The height in portrait and the height in landscape measured in points.

like image 366
Erik B Avatar asked Jul 01 '12 17:07

Erik B


People also ask

Can you make iPhone keyboard taller?

To make your iPhone keyboard bigger, change your display settings to make the entire UI bigger. Alternatively, you can install a third-party app such as Larger Keyboard or TuneKey. If you don't like the results, you can buy an iPhone Pro Max and upgrade to a bigger display.

What is onscreen keyboard on iPhone?

In apps on iPhone, you can use the onscreen keyboard to enter and edit text. You can also use Magic Keyboard and Dictation to enter text.

Why is my iPhone keyboard so high?

You can turn the split keyboard off in Settings>General>Keyboard>Split Keyboard>Off. You can turn the split keyboard off in Settings>General>Keyboard>Split Keyboard>Off.

Why is iPhone keyboard vertical?

Check and see if your iPhone's portrait orientation lock is in the top screen status bar. If so, turn it off by swiping up from screen bottom to open the Control Center, then tap to unlock. to learn more about control center, check out this article.


2 Answers

I used the following approach for determining the frame of the keyboard in iOS 7.1.

In the init method of my view controller, I registered for the UIKeyboardDidShowNotification:

NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(keyboardOnScreen:) name:UIKeyboardDidShowNotification object:nil]; 

Then, I used the following code in keyboardOnScreen: to gain access to the frame of the keyboard. This code gets the userInfo dictionary from the notification and then accesses the NSValue associated with UIKeyboardFrameEndUserInfoKey. You can then access the CGRect and convert it to the coordinates of the view of your view controller. From there, you can perform any calculations you need based on that frame.

-(void)keyboardOnScreen:(NSNotification *)notification   {         NSDictionary *info  = notification.userInfo;         NSValue      *value = info[UIKeyboardFrameEndUserInfoKey];          CGRect rawFrame      = [value CGRectValue];         CGRect keyboardFrame = [self.view convertRect:rawFrame fromView:nil];          NSLog(@"keyboardFrame: %@", NSStringFromCGRect(keyboardFrame));  } 

Swift

And the equivalent implementation with Swift:

NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil)   @objc func keyboardDidShow(notification: Notification) {     guard let info = notification.userInfo else { return }     guard let frameInfo = info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return }     let keyboardFrame = frameInfo.cgRectValue     print("keyboardFrame: \(keyboardFrame)") } 
like image 196
Ken Anderson Avatar answered Oct 12 '22 19:10

Ken Anderson


Do remember that, with iOS 8, the onscreen keyboard's size can vary. Don't assume that the onscreen keyboard will always be visible (with a specific height) or invisible.

Now, with iOS 8, the user can also swipe the text-prediction area on and off... and when they do this, it would kick off an app's keyboardWillShow event again.

This will break a lot of legacy code samples, which recommended writing a keyboardWillShow event, which merely measures the current height of the onscreen keyboard, and shifting your controls up or down on the page by this (absolute) amount.

enter image description here

In other words, if you see any sample code, which just tells you to add a keyboardWillShow event, measure the keyboard height, then resize your controls' heights by this amount, this will no longer always work.

In my example above, I used the sample code from the following site, which animates the vertical constraints constant value.

Practicing AutoLayout

In my app, I added a constraint to my UITextView, set to the bottom of the screen. When the screen first appeared, I stored this initial vertical distance.

Then, whenever my keyboardWillShow event gets kicked off, I add the (new) keyboard height to this original constraint value (so the constraint resizes the control's height).

enter image description here

Yeah. It's ugly.

And I'm a little annoyed/surprised that Xcode 6's horribly-painful AutoLayout doesn't just allow us to attach the bottoms of controls to either the bottom of the screen, or the top of onscreen keyboard.

Perhaps I'm missing something.

Other than my sanity.

like image 32
Mike Gledhill Avatar answered Oct 12 '22 21:10

Mike Gledhill