如何为我的应用创建自定义键盘

how to create custom keyboard for my app

我需要在我的(而且只有我的)iOS8 应用程序中为某些 TEdit 创建自定义键盘。其他编辑需要默认 iPad 键盘。

在 Objective-C 中看起来很简单 - 只需创建 UIView 并将其分配给 myTextField.inputView (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/index.html#//apple_ref/occ/instp/UITextField/inputView)。

我如何在 FMX (Delphi XE7) 中执行此操作?

更新。 iOSapi.UIKit.pas中声明的UITextField及其对应的控件是FMX.Edit.iOS.pas中的TiOSNativeEdit。 在 TEdit 中,它用于 PresentationProxy 属性,但 仅当 ControlType = Platform 时。 例如:

var
  intf: UITextField;
begin
  if edit1.PresentationProxy.HasNativeObject
    and (edit1.PresentationProxy.NativeObject.QueryInterface(UITextField, intf) = S_OK) then
    edit1.Text := 'Success'
  else
    edit1.Text := 'Failed';

获得 UITextField 接口后(我认为)你可以这样做:

intf.setInputView(myCreatedUIView);

但是...我使用样式控件,所以这种方法不适合我。

所以我必须使用 TFrame、TLayout 等来模拟键盘...

在分析了FMX的源码后,找到了解决办法(只针对IOS)。不幸的是,它太大了,无法包含在这里...

简而言之:您必须使用 FMX.Types.RegisterShowVKProc(myKeyboardProc) 然后你可以选择使用你的键盘,但失去了系统键盘、键盘工具栏和与它们交互的标准机制。

所以,我创建了数字键盘和字母键盘并使用它们。

我的源代码:custom keyboard for iOS

使用方法:在你的项目中包含uCommonCustomKeyboard.pas(这是主机),ufrFullKeyboard.pas和ufrCustomNumpad.pas。就这样。如果 Delphi 说 "error reading property..." 回答 "Cancel" - 这是因为 Delphi 不识别 TFrame 继承。有关支持的键盘类型,请参阅 SupportedKeyboardTypes class 函数