如何检测数字和十进制键盘iOS



我正在开发一个自定义键盘,根据苹果应用商店审查指南,我必须为十进制和数字键盘提供一个键盘:

Keyboard extensions must provide Number and Decimal keyboard types as described in the App Extension Programming Guide or they will be rejected

所以我必须为Decimal和Number Textfield提供一个键盘,这样我才能检测文本字段类型。

在应用程序扩展编程指南中没有关于数字或十进制键盘的内容,所以如何检测我应该加载十进制键盘或数字键盘的文本字段?

您可以在视图显示之前(在Swift中)获得当前键盘类型。

   override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        // Setup keyboard manager to correct type
        if let inputTraits = self.textDocumentProxy as? UITextInputTraits {
           let keyboardType = inputTraits.keyboardType
           let returnKeyType = inputTraits.returnKeyType
        }
    }

这是我的项目,但为了清晰起见,重新格式化了。我也没有编译它,因为它是一个如此简单的例子。

我发现,在视图可见或即将出现之前,不信任任何扩展API值是很好的,但您也可以在viewDidLoad()中尝试这一点

最新更新