【问题标题】:iPhone - Adding a button to keyboard existing accessory view (keyboard from UIWebView)iPhone - 向键盘现有附件视图添加一个按钮(来自 UIWebView 的键盘)
【发布时间】:2011-08-15 00:34:25
【问题描述】:

我正在寻找一种将按钮添加到键盘附件视图的方法,即在将输入字段触摸到 UIWebView 时出现的按钮,而不使用一些私有功能或一些有问题的技巧。

你知道我该怎么做吗?

注意:我知道如何捕捉键盘显示/隐藏事件。我要问的是如何添加按钮。

【问题讨论】:

标签: iphone button uiwebview keyboard accessoryview


【解决方案1】:

您可以使用UIKeyboardWillShowNotification 执行此操作,查看UIWindow reference 以获取相关信息:

[[NSNotificationCenter defaultCenter]
 addObserver:self selector:@selector(keyboardWillShow:)
 name:UIKeyboardWillShowNotification object:nil];

This notification is raised when a textfield even from a UIWebView is selected.

查看 Apple KeyboardAccessory 示例代码,其中显示了如何执行此操作。该示例代码使用 UITextXxxx inputAccessoryView 属性,我怀疑您将能够使用它。但是通知会为您提供足够的信息,让您可以直接在视图中甚至在 UIWindow 顶部添加您的配件,甚至可以通过键盘对其进行动画处理:

(gdb) po notification
NSConcreteNotification 0xb5a2190 {name = UIKeyboardWillShowNotification; userInfo = {
    UIKeyboardAnimationCurveUserInfoKey = 0;
    UIKeyboardAnimationDurationUserInfoKey = "0.300000011920929";
    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 260}}";
    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 610}";
    UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 350}";
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 480}, {320, 260}}";
    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 220}, {320, 260}}";
}}

【讨论】:

    【解决方案2】:

    UIKit 允许应用程序用自定义输入视图代替系统键盘。它还使应用程序能够在系统键盘或自定义输入视图上方具有附件视图。此外,它还使应用程序能够在用户点击输入视图或输入附件视图的控件时播放按键声音。

    更多信息请参考here

    【讨论】:

      【解决方案3】:

      看看this apple example,因为它完全符合您的要求。但总的来说,这个想法是替换 UIWebView 的 inputAccessoryView 以显示您的自定义视图。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-09-04
        • 1970-01-01
        • 1970-01-01
        • 2011-05-20
        • 1970-01-01
        • 1970-01-01
        • 2016-04-07
        • 1970-01-01
        相关资源
        最近更新 更多