8

There is a button at bottom right of iPad keyboard which is to hide the keypad.

enter image description here

How can I interact with it programmatically? (get the button then send UIControlEventTouchUpInside to it).

Does anyone know this?

[Edit] In my case, the keyboard is shown on a modal view.

Son Nguyen
  • 3,481
  • 4
  • 33
  • 47
  • 1
    is this a different behavior than sending -(void)dismissFirstResponder to the view that you are editing? – Grady Player Apr 29 '11 at 06:50
  • In my case, resignFirstResponder does not work since I want to hide iPad keyboard on a modal view (UIModalPresentationFormSheet) to display UIDatePicker, so I would like to fire that event to hide keypad if possible – Son Nguyen Apr 29 '11 at 07:07
  • If you present the UIDatePicker and make it the first responder, the keyboard should go away, no? Why isn't that good enough? – ipmcc May 01 '11 at 15:03
  • hi IPMCC, let me try it, thanks – Son Nguyen May 04 '11 at 04:26
  • 1
    I was looking for the same thing and this worked for me: http://stackoverflow.com/a/6268520 – lockysoft Jan 26 '12 at 23:26

3 Answers3

2

Overriding disablesAutomaticKeyboardDismissal to return NO as below allows you to dismiss the keyboard when you resignFirstResponder, even when your UITextView is on a modal view. You should put this code to your view controller, from which you initiate the keyboard:

- (BOOL)disablesAutomaticKeyboardDismissal {
    return NO;
}

Source: https://stackoverflow.com/a/6268520

Community
  • 1
  • 1
lockysoft
  • 21
  • 3
  • Welcome to Stack Overflow! Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – jjnguy Jan 26 '12 at 23:53
1

Something like this? I can't remember where I found this code but I used it to toggle the on-screen keyboard because it would be hidden by default if a bluetooth one was connected.

- (void) toggleKeyboard(UIKeyboardImpl * keyImpl){

    if (UIKeyboardAutomaticIsOnScreen()) {
        UIKeyboardOrderOutAutomatic();
    } else {
    UIKeyboardOrderInAutomatic();
}

Edit


I found where I got this code from. It works fine but the catch is that you need to import the private framework GraphicsServices, which would most likely get your app rejected from the App store.

Community
  • 1
  • 1
David
  • 7,310
  • 6
  • 41
  • 63
1

In general, you would send the resignFirsResponder message to the active input view.

titaniumdecoy
  • 18,900
  • 17
  • 96
  • 133