我目前正在创建一个iOS 8自定义键盘扩展,并且正在寻找一种方法来确定用户何时切换到另一个输入,以更改我的布局。
例如,当用户选择一个UITextField
类型UIKeyboardTypeEmailAddress
,我打算提出一个自定义的键盘,当用户选择另一种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
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句