gpt4 book ai didi

objective-c - 检测 iOS 8 自定义键盘中的键盘类型更改

转载 作者:太空狗 更新时间:2023-10-30 03:32:26 24 4
gpt4 key购买 nike

我目前正在创建一个 iOS 8 自定义键盘扩展,我正在寻找一种方法来确定用户何时切换到另一个输入,以便更改我的布局。

例如,当用户选择类型为 UIKeyboardTypeEmailAddressUITextField 时,我打算显示一个自定义键盘,当用户选择另一个 UITextField 使用 UIKeyboardTypeDecimalPad 类型,我想注意到它,并更新我的键盘布局。如何在键盘类型更改时收到通知以更新键盘布局?

最佳答案

您可以在 textDidChange 中检测键盘类型的更改。您需要获取 UITextDocumentProxy,然后检查代理的 keyboardType。如果它是您想要支持的键盘类型,则可以显示相应的 UI。例如,这是您检测何时应显示电子邮件键盘的方式:

override func textDidChange(textInput: UITextInput) {
// Called when the document context is changed - theme or keyboard type changes

var proxy = self.textDocumentProxy as UITextDocumentProxy
if proxy.keyboardType == UIKeyboardType.EmailAddress {
//add code here to display email input keyboard
}
}

关于objective-c - 检测 iOS 8 自定义键盘中的键盘类型更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26105066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com