Search code examples
iosxcodeswiftkeyboardstoryboard

How to make iOS keyboard appear/stay up during entire app lifecycle?


I want to know how to make the keyboard appear in an iOS Swift app and remain there permanently. I know it appears when the user touches inside a textfield. That's not what I want. I want it to be there when the user loads up the app and to stay there permanently. I do still want the keyboard to communicate with a textfield as it normally would.

I would also like to be able to use the keyboard in storyboard auto layout and scale/align my buttons around the keyboard, which is asked here:
Xcode storyboard layout size simulation - keyboard up?

What I tried:

If I could simulate a "touch" inside a textfield programmatically I think I can accomplish my task. I would forcibly simulate a "touch" once the app loads and then in the "textFieldShouldReturn" method I can repeat the forced programmatic touch inside the textfield to prevent the keyboard from disappearing. (This may cause the keyboard to disappear and then reappear quickly, which would be ugly and undesirable.) How do I force this fake touch?

In Conclusion:

I am using iOS Storyboard and Swift.

How do I cause a keyboard to load up on start up and remain there even after pressing return/send?

If the above is impossible, how do I programattically force a touch inside a textfield?


Solution

  • I think that you can't do this from storyboard side, but from code side, assuming that you name your textfield "textField", you can do self.textField.becomeFirstResponder() on your viewDidLoad() in order to make the keyboard appear when you enter on this screen. This should keep the keyboard on screen unless you do resignFirstResponder() elsewhere.