【问题标题】:how to create custom keyboard for my app如何为我的应用创建自定义键盘
【发布时间】:2015-08-02 04:51:30
【问题描述】:

我需要在我的(并且只有我的)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 等来模拟键盘......

【问题讨论】:

    标签: delphi ios8 firemonkey delphi-xe7


    【解决方案1】:

    在分析了FMX的源码后,找到了解决方案(仅限IOS)。不幸的是,它太大了,无法在此处包含它...

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

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

    我的源码:custom keyboard for iOS

    如何使用:在你的项目中包含 uCommonCustomKeyboard.pas(这是主单元)、ufrFullKeyboard.pas 和 ufrCustomNumpad.pas。就这样。如果 Delphi 说“错误读取属性...”回答“取消” - 这是因为 Delphi 无法识别 TFrame 继承。支持的键盘类型见SupportedKeyboardTypes类函数

    【讨论】:

      猜你喜欢
      • 2011-06-06
      • 1970-01-01
      • 2016-12-10
      • 2022-09-23
      • 2016-04-25
      • 2012-01-09
      • 2018-02-26
      相关资源
      最近更新 更多