简体   繁体   English

自定义键盘附件视图输入

[英]Custom Keyboard Accessory view input

I have created a custom accessory view to supplement the standard Apple alpha iOS keyboard.我创建了一个自定义附件视图来补充标准 Apple alpha iOS 键盘。 The purpose is to add a line of numeric keys to prevent flipping back and forth between keyboard views.目的是添加一行数字键,以防止在键盘视图之间来回翻转。 At first, I created a toolbar and loaded it with a set of 0 - 9 titled buttonItems and it functioned quite well.起初,我创建了一个工具栏并加载了一组 0 - 9 个标题为 buttonItems 的工具栏,它运行得很好。 However, it looked terrible, not at all like the alpha keys despite adding a rounded rect background image to each key because the system apparently prevents customizing font size and button spacing inside the stack view of the toolbar.然而,它看起来很糟糕,尽管为每个键添加了一个圆角矩形背景图像,但它一点也不像 alpha 键,因为系统显然阻止了在工具栏的堆栈视图内自定义字体大小和按钮间距。 Therefore, I created a UIView xib and loaded it with a stackView full of customized numerical buttons.因此,我创建了一个 UIView xib 并加载了一个充满自定义数字按钮的 stackView。 When I add the UIView as the accessory view it looks pretty darn close to the rest of the Apple Alpha keyboard.当我添加 UIView 作为附件视图时,它看起来非常接近 Apple Alpha 键盘的 rest。 The issue now is that the touch-up events go to the UIView class of the accessory view.现在的问题是附件视图的 go 到 UIView class 的修饰事件。 Is there a clever, efficient way to have the button presses in the accessory emulate the std keyboard feeding into TextField: shouldChangeCharactersIn?是否有一种聪明、有效的方法可以让附件中的按钮按下模拟输入到 TextField 的标准键盘:shouldChangeCharactersIn? I could package the button presses into a local notification event to get it into the class holding the textField but that seems terribly inelegant.我可以 package 按钮按下本地通知事件以使其进入持有 textField 的 class 但这似乎非常不雅。 Any suggestions would be greatly appreciated.任何建议将不胜感激。 Stay Safe!注意安全!

Not the best answer, but I did implement notification on key button press with an observer in the main view class.不是最佳答案,但我确实在主视图 class 中使用观察者实现了按键按下通知。 The observer does a TextField.insertText which is suboptimal since I will need to refactor the several hundred lines of code that performs real-time language translation in the shouldChangeCharacters methods.观察者执行了一个次优的 TextField.insertText,因为我需要重构在 shouldChangeCharacters 方法中执行实时语言翻译的数百行代码。 Ah well.呃,好吧。

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

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