0

The default software keyboard on iOS when running on an iPad has a "dismiss" button to hide the keyboard. It's located in the bottom-right corner.

Is there a way to detect specifically this configuration... or that this button exists... aside from checking whether the device is an iPad or not? For example, for devices WITHOUT this button (iPhone/iPod Touch), maybe we would want to add a button outside of the keyboard to do this, but wouldn't want two separate buttons to exist if there was one already on iPad.

iPad software keyboard photo

Ben Guild
  • 4,881
  • 7
  • 34
  • 60

2 Answers2

1

I don't think that exist a way to specifically ask if a keyboard supports its, but what you can do is ask the idiom of device:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

}
else {

}

Or, since also 6 and 6plus supports that button in landscape you can ask the UITraitCollection of the device in that specific moment, if it is regular the dismiss button on the keyboard will be displayed, but is kind of a strong hypothesis.
Before presenting the keyboard try to check horizontal traits.

if view.traitCollection.horizontalSizeClass == .Regular {
        // has the dismiss button
    }
    else {
        // add an accessory input view
    }
Andrea
  • 26,120
  • 10
  • 85
  • 131
  • It says in the question above "Is there a way to detect specifically this configuration... or that this button exists... **aside from checking whether the device is an iPad or not?**" – Ben Guild Jul 12 '16 at 08:10
  • @BenGuild Checking traits is not checking device, besides we are trying to help, downvoting won't – Andrea Jul 12 '16 at 08:13
  • Your source code includes checking for a match with `UIUserInterfaceIdiomPad`. – Ben Guild Jul 12 '16 at 08:41
  • yes the other one was a suggestion. I've update my answer with a snippet , SWIFT since you did not specify the language. – Andrea Jul 12 '16 at 08:50
  • Is it possible to remove the "keyboard hide button"? – Ne AS Jul 19 '17 at 09:37
  • @Llg It doesn't seems possible, unless you build a custom keyboard and a user installs and uses it – Andrea Jul 19 '17 at 10:27
  • Okay thank you. Is there a way to detect when this button is tapped without the `NSNotificationCenter ` way? Because I did the same as the accepted answer here https://stackoverflow.com/questions/12322137/uikeyboardwillhide-not-triggered but when i tap the button my app crashes – Ne AS Jul 19 '17 at 10:30
-1

You can set below things

[textField resignFirstResponder];  

or

[textField setReturnKeyType:UIReturnKeyDone];  

and other different types

S1LENT WARRIOR
  • 11,704
  • 4
  • 46
  • 60
Nattudurai
  • 856
  • 7
  • 9
  • That's not what's being asked. I'm asking if there's a way to see if the button exists, not if it has been pressed. – Ben Guild Jul 12 '16 at 08:09