Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swap out a custom inputView for the standard keyboard in iOS

I have a custom inputView for a particular textfield, and it works well. However, I cannot discern how to dismiss the view and get the regular keyboard back. (I have a SWAP button right next to the TextField.) I tried setting the textfield's inputView to nil, but that did nothing.

I do not need a full custom keyboard, but I need more than an Accessory view above the keyboard, which is why I am trying this route. I need about 20 custom buttons in addition to the regular keyboard, and I do not like the idea of a huge Accessory view taking up so much space.

I also would rather not require the user to initially install a full custom keyboard before being able to use the app.

Thank you very much for any suggestions.

like image 637
Craig Smith Avatar asked May 23 '15 19:05

Craig Smith


2 Answers

I think you will probably have to do this:

  1. Call resignFirstResponder on the UITextField
  2. After the animation finishes, set your inputView to nil
  3. Call becomeFirstResponder on the text field

The keyboard animation duration is sent in the userInfo dictionary on the keyboard presentation notifications.

like image 74
bdrell Avatar answered Nov 18 '22 02:11

bdrell


In addition to the accepted answer, you can use reloadInputViews() (and this is less likely to suffer any animation glitches resulting from the resignFirstResponder, becomeFirstResponder calls):

  1. yourTextField.inputView = nil;
  2. yourTextField.reloadInputViews();

Here's more info in the Apple's Docs.

like image 8
adamup Avatar answered Nov 18 '22 03:11

adamup