如何在iOS 8上的自定义键盘中添加数字和十进制键盘?

时间:2014-10-08 14:00:01

标签: ios swift ios8 ios-app-extension custom-keyboard

我在Swift中创建了一个自定义键盘但是它被App Store拒绝了,因为:"键盘扩展名不包括Number和Decimal类型"。

如何轻松添加这两个键盘?

我尝试重建原始视图,但它无法正常工作。我确定有一个解决方案可以创建2个或3个不同的视图并在它们之间切换。

键盘类型更改时,如何在键盘类型之间切换?

1 个答案:

答案 0 :(得分:4)

您可以在textDidChange中检测键盘类型的更改。您需要获取UITextDocumentProxy然后检测代理的keyboardType,然后您可以执行所需的布局更改。

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

    let proxy = self.textDocumentProxy as UITextDocumentProxy
    if proxy.keyboardType == UIKeyboardType.numberPad
        || proxy.keyboardType == UIKeyboardType.decimalPad {
        //add code here to display number/decimal input keyboard
    }
}
相关问题