Search code examples
objective-cioskeyboardfirst-responder

How to make ios keyboard appear manually?


I have a custom view which will act as a text field and another custom view hat acts as its keyboard. I was planning on implementing uikeyinput protocol, but since its a custom keyboard, it can't send messages to its delegate through uikeyinput, so I thought I might as well make a custom protocol as well. After making the text field first responder, how do I program the keyboard to appear when someone clicks the text field?


Solution

  • Declare the property inputView in your custom view class header:

    @property (nonatomic, readonly) MyCustomKeyboardView *inputView;
    

    Don't synthesize it. Instead, explicitly implement the getter in your custom view class to return your custom keyboard view. Once your view becomes first responder Cocoa automatically reads this property to check if your view needs a custom keyboard. It even animates the keyboard in.

    See the documentation for UIResponder.