简体   繁体   English

如何检测数字和小数键盘iOS

[英]how to detect Number and Decimal Keyboard iOS

I'm developing a custom keyboard and based on Apple App Store Review guideline I have to provide a keypad for decimal and number pad : 我正在开发自定义键盘,并且根据Apple App Store审查指南,我必须提供用于小数和数字键盘的小键盘:

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

So I have to provide a keyboard for Decimal and Number Textfield, so how can I detect textfield type. 因此,我必须提供一个用于十进制和数字文本字段的键盘,以便如何检测文本字段类型。

There is nothing about Number or Decimal Keyboard in App Extension Programming Guide so How detect which textfield I should load Decimal Keyboard or Number Keypad ? 应用程序扩展编程指南》中没有关于数字或十进制键盘的内容,因此如何检测应该加载哪个文本字段的“十进制键盘”或“数字键盘”?

You can get the current keyboard type before your view appears like so (in Swift). 您可以在视图显示之前获得当前的键盘类型(在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
        }
    }

This from my project but reformatted for clarity. 这是从我的项目中得出的,但为了清楚起见重新格式化。 I also didn't compile it since it's such a simple example. 由于这是一个简单的示例,因此我也没有对其进行编译。

I've found it's good not to trust any extension API values until the view is visible or about to appear, but you could also try this in viewDidLoad() 我发现在视图可见或即将出现之前不信任任何扩展API值是很好的,但是您也可以在viewDidLoad()中尝试

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

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