How to make UIKeyboard not disappear when UIMenuController becomes first responder

Sometimes we want to not allow UIKeyboard disappear. Look at a chat in “WhatsApp” app. When you click twice on a chat item, keyboard doesn’t disappear. At the same time you see a custom UIMenuController. This is not a default behavior. By default keyboard disappears since to show UIMenuController you need to make your chat item view become first responder.

The most popular way to make this happen is to use an invisible UITextField or UITextView and make it becomeFirstReposnder after menu is shown.

But there is a very elegant solution using UIKeyInput Protocol. I found it also at that place.

Documentation tells

A subclass of UIResponder can adopt this protocol to implement simple text entry. When instances of this subclass are the first responder, the system keyboard is displayed.
Only a small subset of the available keyboards and languages are available to classes that adopt this protocol.

So I decided to use this solution. And it worked perfect! You just need to add this protocol to your class definition. For instance:

One thought on “How to make UIKeyboard not disappear when UIMenuController becomes first responder”

  1. Hi.

    I tried to use this and met one issue: how can i hide this keyboard ?

    i make chat app and on long press of chat text cell i display UIMenuController.
    If system keyboard was displayed before – all works good. But if user hide system keyboard – keyboard created for UIKeyInput still here.

    Maybe you can help me ?

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *