iPhone - Adding a button to keyboard existing accessory view (keyboard from UIWebView)

限于喜欢 提交于 2019-11-26 22:06:12

问题


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.

Do you know how I may do this ?

Note : I know how I may catch the keyboard show/hide events. What I'm asking for is how to add the button.


回答1:


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];

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

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



回答2:


UIKit allows applications to substitute custom input views for the system keyboard. It also enables applications to have an accessory view above the system keyboard or custom input view. Additionally, it enables applications to play key-click sounds when users tap on a controls of an input view or input accessory view.

Refer here for more




回答3:


Take a look at this apple example, as it does exactly what you are searching for. But in general the idea is to replace the inputAccessoryView for the UIWebView in order to show your custom view.



来源:https://stackoverflow.com/questions/5824325/iphone-adding-a-button-to-keyboard-existing-accessory-view-keyboard-from-uiwe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!