iOS - How can I preload the keyboard?

后端 未结 4 1631
滥情空心
滥情空心 2021-01-30 13:43

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 o

4条回答
  •  长情又很酷
    2021-01-30 13:53

    Once a user complain my app of the slow loading keyboard. Here is a little trick to disable the keyboard animation:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        // ...
    
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(willShowKeyboard:)
                                                     name:UIKeyboardWillShowNotification
                                                   object:nil];
    
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(didShowKeyboard:)
                                                     name:UIKeyboardDidShowNotification
                                                   object:nil];
    
        // ...
    }
    
    
    - (void)willShowKeyboard:(NSNotification *)notification
    {
        [UIView setAnimationsEnabled:NO];
    }
    
    - (void)didShowKeyboard:(NSNotification *)notification
    {
        [UIView setAnimationsEnabled:YES];
    }
    

    It may not answer the question directly, as the keyboard itself is in the main UI for my example and caching is not the option to me. Nevertheless, the overall responsiveness is improved.

提交回复
热议问题