简体   繁体   English

像在iPad上一样,检测iOS设备的键盘是否具有“键盘隐藏按钮”?

[英]Detect if iOS device's keyboard has the “keyboard hiding button”, like on iPad?

The default software keyboard on iOS when running on an iPad has a " dismiss " button to hide the keyboard. 当在iPad上运行时,iOS上的默认软件键盘具有“ 关闭 ”按钮以隐藏键盘。 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? 除了检查设备是否为iPad外,是否有办法专门检测此配置...或该按钮是否存在? 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. 例如,对于没有此按钮的设备(iPhone / iPod Touch),也许我们想在键盘外部添加一个按钮来执行此操作,但是如果iPad上已经存在一个按钮,则我们不希望存在两个单独的按钮。

iPad软件键盘照片

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. 或者,由于6和6plus也支持横向按钮,因此您可以在特定时刻询问设备的UITraitCollection ,如果正常,将显示键盘上的关闭按钮,但这是一个很强的假设。
Before presenting the keyboard try to check horizontal traits. 出现键盘之前,请尝试检查水平特征。

if view.traitCollection.horizontalSizeClass == .Regular {
        // has the dismiss button
    }
    else {
        // add an accessory input view
    }

You can set below things 您可以设置以下内容

[textField resignFirstResponder];  

or 要么

[textField setReturnKeyType:UIReturnKeyDone];  

and other different types 和其他不同类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM