本文介绍了iPhone - 向键盘现有附件视图添加一个按钮(来自 UIWebView 的键盘)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm searching a way to add a button into the accessory view of a keyboard, the one that comes up when touching an input field into a UIWebView, without using some private functions or some questionable tricks.

你知道我该怎么做吗?

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

推荐答案

您可以使用 UIKeyboardWillShowNotification 查看 UIWindow 参考了解它的信息:

You can do this using UIKeyboardWillShowNotification look into UIWindow reference for information about it :

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

当文本字段甚至来自 UIWebView 被选中时,会引发此通知.

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

看看苹果 KeyboardAccessory 示例代码展示了如何执行此操作.该示例代码使用 UITextXxxx inputAccessoryView 属性,我怀疑您是否能够使用.但是通知会给你足够的信息来直接在你的视图中添加你的附件,甚至在顶部的 UIWindow 上,甚至通过键盘动画:

Look at Apple KeyboardAccessory Sample code which shows how to do this. That sample code use the UITextXxxx inputAccessoryView property, that I doubt you will be able to use. But the notification will give you enough information to add your accessory directly in your view or even on top UIWindow, and that even by animating it with the keyboard :

(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}}";
}}

这篇关于iPhone - 向键盘现有附件视图添加一个按钮(来自 UIWebView 的键盘)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 16:36
查看更多