Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - How can I preload the keyboard?

The Problem

In most iPhone apps, there's a quite a bit of delay the first time that the keyboard is presented (presumably creating the keyboard takes quite a bit of oomph, even on an iPhone 4).

Most people seem ok with this. I'm not, it really bugs me - and the way my app is presented, users will be very confused that nothing happens for a few seconds when they tap on a text field for the first time.


What I've Tried

Googling it brings up one solution - unfortunately this is invalid as of iOS 4 (see here).

I don't expect the solution to be easy to find, if I could put a bounty on this straight away I would. I would be very stoked if someone figured out a solution. All the solution needs to do is load the keyboard without the user being aware.


So..

Any ideas are appreciated. Complete, working code (for iOS 4 and 5) is bounty worthy (even if the bounty has to come later!).

If a solution is found I plan to create a self contained 'KeyboardPreloader' class that people can drop into their project, and preload the keyboard with one line of code :)

like image 477
Jordan Smith Avatar asked Feb 02 '12 06:02

Jordan Smith


People also ask

How do I get my iPhone keyboard back to normal?

Go to Settings > Accessibility > Keyboards, tap Full Keyboard Access, then turn on Full Keyboard Access.

Can you change the iPhone keyboard?

Go to Settings > General > Keyboard. Tap Keyboards, then do any of the following: Add a keyboard: Tap Add New Keyboard, then choose a keyboard from the list. Repeat to add more keyboards.

Can you resize iPhone keyboard?

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.


2 Answers

UIResponder+KeyboardCache was written to address this exact problem.

From that project's readme:

This category on UIResponder gives you a simple method +cacheKeyboard so that you can control when this caching work is done. For example, if you are loading some data from a server, then you could invoke this during that downtime. There is another method +cacheKeyboard: that takes an optional BOOL value. Passing YES to this method causes the cache invocation to happen on the next runloop. So, if you performed an animation just before calling this method it would not interrupt that animation.

like image 186
cbowns Avatar answered Sep 21 '22 10:09

cbowns


making the textfield the firstResponder and then resigning it in the viewdidload.. this seems to work with no lag when the keyboard is loaded again...

- (void)viewDidLoad {     [super viewDidLoad];      [textField becomeFirstResponder];     [textField resignFirstResponder];         // Do any additional setup after loading the view, typically from a nib. } 
like image 42
Ankit Srivastava Avatar answered Sep 24 '22 10:09

Ankit Srivastava